﻿<%@ WebHandler Language="C#" Class="ShowListBargain" %>

using System;
using System.Web;
using System.Text;
using System.Collections.Generic;
using System.Data;
using Chenxin.Lib.Utility;
using Chenxin.Lib.Business;
using Chenxin.Lib.Business.BLL;
public class ShowListBargain: AjaxHandlerBase
{
    //*******************************************
    //功能概要       ：基本权限初始化设定
    //参数説明       ： 
    //返回值説明     ：-
    //功能詳細       ：-
    //作成者         ：chen.yugong 
    //作成日         ：2010-06-29
    //修改者         ：
    //修改日         ：2010-07-13
    //*******************************************
    private Chenxin.Lib.Business.BLL.ConfirmMainBusinessApply confirmMainBusinessApply  = null;
    
    public ShowListBargain()
    {
        confirmMainBusinessApply = new Chenxin.Lib.Business.BLL.ConfirmMainBusinessApply();
        //上传交易附件权限
        htTypePermit.Add("uploadatt", Constants.Permit_AddContractAtt);
        //修改成交记录
        htTypePermit.Add("confirmedit", Constants.Permit_Bargain_Edit);
        //作废成交记录
        htTypePermit.Add("cancelcode", Constants.Permit_Bargain_CancelCode);
        //成交记录--解封全部
        htTypePermit.Add("openall", Constants.Permit_Bargain_OpenAll);
        //成交记录--封帐
        htTypePermit.Add("closeaccount", Constants.Permit_Bargain_CloseAccount);
        //成交记录--解封资料
        htTypePermit.Add("opendata", Constants.Permit_Bargain_OpenData);
        //成交记录--解封佣金
        htTypePermit.Add("opencommission", Constants.Permit_Bargain_OpenCommission);
        //成交记录--解封点数
        htTypePermit.Add("openpoint", Constants.Permit_Bargain_OpenPoint);
        //成交记录--解封点数
        htTypePermit.Add("openflaw", Constants.Permit_Bargain_OpenFlaw);
        //成交记录--取消业绩
        htTypePermit.Add("cancelarchivement", Constants.Permit_Bargain_CancelArchivement);
        //成交记录--取消业绩
        htTypePermit.Add("creatarchivement", Constants.Permit_Bargain_CreatArchivement);
        //成交记录--应收登记
        htTypePermit.Add("regincome", Constants.Permit_Bargain_Regincome);
        //成交记录--收付开单
        htTypePermit.Add("addbillpay", Constants.Permit_Bargain_AddBillPay);
        //成交记录--个案补证
        htTypePermit.Add("deallackitems", Constants.Permit_Bargain_LackItems);
        //成交记录--佣金调整
        htTypePermit.Add("adjcomm", Constants.Permit_Bargain_Adjcomm);
        //成交记录--导出
        htTypePermit.Add("export", Constants.Permit_Bargain_Export);
        htTypePermit.Add("exportall", Constants.Permit_Bargain_Export);  
        //成交记录--查看
        htTypePermit.Add("view", Constants.Permit_Bargain_View);
        //成交记录--特殊折让
        htTypePermit.Add("discount", Constants.Permit_Bargain_Discount);    
         //成交记录--调整率更新
        htTypePermit.Add("relative", Constants.Permit_Bargain_DiscountRate);                  
    }

    //*******************************************
    //功能概要       ：请求处理
    //参数説明       ：context 请求上下文
    //返回值説明     ：-
    //功能詳細       ：根据请求名 分发请求
    //作成者         ：chen.yugong 
    //作成日         ：2010-06-29
    //修改者         ：
    //修改日         ：2010-07-13
    //*******************************************
    override public void RequestProcess(HttpContext context)
    {
        context.Response.ContentType = "text/plain";
        context.Response.AddHeader("pragma", "no-cache");
        context.Response.AddHeader("cache-control", "");
        context.Response.CacheControl = "no-cache";
        
        string strOp = context.Request["op"];
        string strResponse = "";
        string FilePath = Constants.FilePath_Contract;
        
        switch (strOp.ToLower())
        {
            //调整率
            case "relative":
                strResponse = Relative(context);
                break;
            //查询
            case "getlist":
                strResponse = getList(context);
                break;
            case "getmultilist":
                strResponse = GetMultiList(context);
                break;
            //特殊折让
            case "discount":
                strResponse = Discount(context);
                break;
            //查询
            case "getmodel":
                strResponse = getModel(context);
                break;
            //解封全部
            case "openall":
                strResponse = updateStatus(context);
                break;
            //封帐
            case "closeaccount":
                strResponse = updateStatus(context);
                break;
             //解封资料
            case "opendata":
                strResponse = updateStatus(context);
                break;
            //解封佣金
            case "opencommission":
                strResponse = updateStatus(context);
                break;                 
             //解封点数
            case "openpoint":
                strResponse = updateStatus(context);
                break;                  
            //解封瑕疵
            case "openflaw":
                strResponse = updateStatus(context);
                break;  
                
            //得到生成业绩实体
            case "getarchivement":
                strResponse = GetArchivement(context);
                break;
            //生成业绩
            case "creatarchivement":
                strResponse = CreatArchivement(context);
                break;
            //取消业绩
            case "cancelarchivement":
                strResponse = CancelArchivement(context);
                break;
            //收付开单
            case "addbillpay":
                strResponse = addBillPayment(context);
                break;
            //余款
            case "getremain":
                strResponse = getRemainPayment(context);
                break;
            //获取补证信息
            case "getlackitemsinfo":
                strResponse = getLackItemsInfo(context);
                break;
            //添加或更新补证信息
            case "deallackitems":
                strResponse = dealLackItems(context);
                break;
            case "fileupload":
                Fileupload(context, FilePath);
                break;
            //保存附件信息
            case "uploadatt":
                strResponse = addContractAtt(context);
                break;
            //检查意向书编号
            case "chkintentioncode":
                strResponse = chkIntentionCode(context);
                break;
            //业绩调整历史
            case "gethistory":
                strResponse = getAdjustInfoList(context);
                break;
            //获取调整前，实际收付金额
            case "getmomey":
                strResponse = getBeforeRealMoney(context);
                break;
            //佣收调整
            case "adjcomm":
                strResponse = adjestCommision(context);
                break;
            //应收登记
            case "regincome":
                strResponse = regIncome(context);
                break;
            //获取应收历史
            case "getincomehistory":
                strResponse = getIncomeHistory(context);
                break;
            case "cancelcode":
                strResponse = CancelCode(context);
                break;
            //导出全部
            case "exportall":
                ExportAll(context);
                return;
            //得到调整历史数据
            case "getrelative":
                strResponse = GetRelative(context);
                break;
            default:
                break;
        }
        context.Response.Write(strResponse);
    }

    private string GetRelative(HttpContext context)
    {
        string modelid = context.Request["modelid"];

        //页码
        int strPageIndex = (string.IsNullOrEmpty(context.Request["pageindex"])) ? 1 : int.Parse(context.Request["pageindex"]) + 1;//页码
        //页显示行数
        int strPageSize = (string.IsNullOrEmpty(context.Request["pagesize"])) ? 30 : int.Parse(context.Request["pagesize"]);//页记录数
        string strOrderField = "addtime desc";

        string TableName="t_Contract_DiscountRateHistory as a left join t_Contract_BaseInfo as b on a.ContractId=b.ContractId";

        string FieldList = "ContractId,ContractCode,HouseAddress,DiscountRate,Addtime,AddPerson";

        string TableFieldList = "a.ContractId,b.ContractCode,b.HouseAddress,a.DiscountRate,a.Addtime,a.AddPerson";

        DataSet ds = Chenxin.Lib.Business.DAL.System_TraceInfo.GetList(strPageIndex, strPageSize, strOrderField, TableName, "a.ContractId='"+modelid+"'", FieldList, TableFieldList, true);
        
        return string.Format("{{success:1,msg:'',data:{{count:{0},{1}}}}}", ds.Tables[1].Rows[0][0], Chenxin.Lib.Utility.JsonHelp.Convert2Json(ds.Tables[0]));
    }
    
    
    //调整率
    private string Relative(HttpContext context)
    {
        string modelid = context.Request["modelid"];
        string DiscountRate = "1";
        if (!string.IsNullOrEmpty(context.Request["DiscountRate"]))
            DiscountRate = context.Request["DiscountRate"];
        
        Chenxin.Lib.Business.Entity.t_Contract_BaseInfo entinfo = Chenxin.Lib.Business.DAL.t_Contract_BaseInfo.GetModel(new Guid(modelid));
        Chenxin.Lib.Business.Entity.t_Contract_CommisionInfo entcomm = Chenxin.Lib.Business.DAL.t_Contract_CommisionInfo.GetModel(new Guid(modelid));
        
        entinfo.DiscountRate = decimal.Parse(DiscountRate);
        entinfo.RateDate = DateTime.Now;
        entcomm.DiscountRateFinal = decimal.Parse(DiscountRate);
        
        Chenxin.Lib.Business.DAL.t_Contract_BaseInfo.Update(entinfo);
        Chenxin.Lib.Business.DAL.t_Contract_CommisionInfo.Update(entcomm);
        
        Chenxin.Lib.Business.Entity.t_Contract_DiscountRateHistory history = new Chenxin.Lib.Business.Entity.t_Contract_DiscountRateHistory();
        history.RecordId = Guid.NewGuid();
        history.ContractId = new Guid(modelid);
        history.DiscountRate = decimal.Parse(DiscountRate);
        history.Addtime = DateTime.Now;
        history.AddPerson = CurrentUserInfo.UserName;

        Chenxin.Lib.Business.DAL.t_Contract_DiscountRateHistory.Add(history);

        string text = string.Empty;
        text = CurrentUserInfo.UserName + "：调整率更新。成交编号：" + entinfo.ContractCode;
        AddLog(text, BusinessType.BusinessTypeComboList()["OprType_DiscountRate"].ToString());

        return string.Format("{{success:'1',msg:'{0}',data:''}}", "调整率更新成功！");
    }
    
    
    //特殊折让
    private string Discount(HttpContext context)
    {
        Chenxin.Lib.Business.Entity.t_Contract_BaseInfo baseinfo = (Chenxin.Lib.Business.Entity.t_Contract_BaseInfo)JsonHelp.Convert2Entity(context.Request["model"], typeof(Chenxin.Lib.Business.Entity.t_Contract_BaseInfo));
        Chenxin.Lib.Business.Entity.t_Contract_BaseInfo entinfo = Chenxin.Lib.Business.DAL.t_Contract_BaseInfo.GetModel(baseinfo.ContractId);
        Chenxin.Lib.Business.Entity.t_Contract_CommisionInfo entcomm = Chenxin.Lib.Business.DAL.t_Contract_CommisionInfo.GetModel(baseinfo.ContractId);

        entinfo.VSTDiscount = entcomm.VSTDiscountFinal = baseinfo.VSTDiscount;
        entinfo.BSTDiscount = entcomm.BSTDiscountFinal = baseinfo.BSTDiscount;
        entinfo.STMemo = baseinfo.STMemo;

        Chenxin.Lib.Business.DAL.t_Contract_BaseInfo.Update(entinfo);
        Chenxin.Lib.Business.DAL.t_Contract_CommisionInfo.Update(entcomm);

        string text = string.Empty;
        text = CurrentUserInfo.UserName + "：特殊折让。成交编号：" + entinfo.ContractCode;
        AddLog(text, BusinessType.BusinessTypeComboList()["OprType_Discount"].ToString());

        return string.Format("{{success:'1',msg:'{0}',data:''}}", "特殊折让成功！");
    }
    
//导出全部数据
    private void ExportAll(HttpContext context)
    {
        try
        {
            string showtype = context.Request["showtype"];
            //排序
            string strOrderField = "a.AddTime desc";
            
            string TableName = "t_Contract_BaseInfo a inner join t_Contract_CommisionInfo b on a.contractId = b.ContractId left Join t_Contract_LackItemsInfo c on a.ContractId = c.ContractId ";
            
            //查询条件
            string sqlWhere = GenerateCondition(context);
            
             StringBuilder sb = new StringBuilder();
             sb.Append("ContractUserName,a.ContractId,ApplyId,ContractCode,CONVERT(Varchar(10),ContractDate,102) as ContractDate,BusinessDescribe,BusinessType,CustomerSource,a.Status,");
            sb.Append("case BargainType when 10 then '面签' else '授签' end as BargainType,BargainPrice,HouseId,");
            sb.Append("HouseAddress,Area,CommunityId,Community,PropertyCode,Region,Block,CurrentFloor,LackDocument,");
            sb.Append("TotalFloor,BuildingType,HouseUse,HouseType,BargainCompanyName,VenderDepartId,VenderDepartName,");
            sb.Append("VenderUserId,VenderUserName,VenderId,VenderName,VenderNo,VenderPhone,VenderMobile,");
            sb.Append("BuyerDepartId,BuyerDepartName,BuyerUserId,BuyerUserName,BuyerId,BuyerName,BuyerNo,BuyerPhone,BuyerMobile,");
            sb.Append("VStanCommision,BStanCommision,AppEmployee,AppDepart,ConfirmEmplyee,ConfirmDepart,a.AddTime as AddTime,");
            sb.Append("a.UpdateTime,bArchivement,LockStatus,CONVERT(Varchar(10),LastCreateArchDate,102) as LastCreateArchDate,CreateArchEmp,PointRemark,CONVERT(Varchar(10),ArchivementDate,102) as ArchivementDate,");
            sb.Append("dbo.f_get_contract_pointallot('Depart',a.ContractId,'10') AS V_Departs," +
                "dbo.f_get_contract_pointallot('Employee',a.ContractId,'10') as V_Users," +
                "dbo.f_get_contract_pointallot('Point',a.ContractId,'10') as V_Points," +
                "dbo.f_get_contract_pointallot('Depart',a.ContractId,'20') AS B_Departs," +
                "dbo.f_get_contract_pointallot('Employee',a.ContractId,'20') as B_Users," +
                "dbo.f_get_contract_pointallot('Point',a.ContractId,'20') as B_Points," +
                "dbo.f_get_contract_pointallot('Depart',a.ContractId,'All') AS Departs," +
                "dbo.f_get_contract_pointallot('Employee',a.ContractId,'All') as Users," +
                "dbo.f_get_contract_pointallot('Point',a.ContractId,'All') as Points,");
            sb.Append("VRealCommisionFinal,BRealCommisionFinal,VCommisionFinal,BCommisionFinal,VConsultingFinal,BConsultingFinal,");
            sb.Append("VCommisionGeted,BCommisionGeted,VConsultingPayed,BConsultingPayed,BCommisionGetedPayed,VCommisionGetedPayed,");
            sb.Append("a.ContractCityId,a.ContractCityName,a.ContractCompanyId,a.ContractCompanyName,a.ContractDepartmentName,Memo,");
            sb.Append("case when VRealCommisionFinal>VCommisionGeted then convert(decimal(18,2),VRealCommisionFinal-VCommisionGeted) else 0 end as VNotGeted,");
            sb.Append("case when BRealCommisionFinal>BCommisionGeted then convert(decimal(18,2),BRealCommisionFinal-BCommisionGeted) else 0 end as BNotGeted");

            string strSql = "select " + sb.ToString() + " from " + TableName + " where " + sqlWhere + " order by " + strOrderField;
            
            //查询分页信息
            System.Data.DataSet ds = Chenxin.Lib.Business.DAL.v_Contract_CommisionDetailInfo.GetList(strSql);

            string strHTML = "";
            strHTML = GetHtml(ds.Tables[0], showtype);

            ExportByServce(context, strHTML);
        }
        catch (Exception ex)
        {
            //return string.Format("{{success:'0',msg:'{0}：{1}',data:''}}", Resources.Message.Global_Err_Exception, ex.Message);
        }
    }   
    
    //得到HTML
    private string GetHtml(DataTable dt,string showtype)
    {
        StringBuilder sb = new StringBuilder();
        switch (showtype)
        {
            case "10":
                sb = GetMainTable(dt);
                break;
            case "20":
                sb = GetMainTable(dt);
                break;
            case "30":
                sb = GetLooseTable(dt);
                break;
            case "40":
                sb = GetOtherTable(dt);
                break;
        }        
        return sb.ToString();
    } 
    
    //主营HTML
    private StringBuilder GetMainTable(DataTable dt)
    {
        StringBuilder sb = new StringBuilder();
        sb.Append("<table class=\"tabsorternew table_archive\"><tr>");
        sb.Append("<th style=\"width:40px;\" rowspan=\"2\">封帐</th>");
        sb.Append("<th style=\"width:40px;\" rowspan=\"2\">业绩</th>");
        sb.Append("<th style=\"width:100px;\" rowspan=\"2\">签约人员</th>");
        sb.Append("<th style=\"width:130px;\" rowspan=\"2\">成交编号</th>");
        sb.Append("<th style=\"width:100px;\" rowspan=\"2\">成交日期</th>");
        sb.Append("<th style=\"width:60px;\" rowspan=\"2\">签约方式</th>");
        sb.Append("<th style=\"width:120px;\">房源门店</th>");
        sb.Append("<th style=\"width:120px;\">上家姓名</th>");
        sb.Append("<th style=\"width:120px;\">上家电话</th>");
        sb.Append("<th style=\"width:80px;\" rowspan=\"2\">客户来源</th>");
        sb.Append("<th style=\"width:60px;\" rowspan=\"2\">区域</th>");
        sb.Append("<th style=\"width:300px;\" rowspan=\"2\">房屋地址</th>");
        sb.Append("<th style=\"width:120px;\" rowspan=\"2\">面积</th>");
        sb.Append("<th style=\"width:120px;\" rowspan=\"2\">合同标的</th>");
        sb.Append("<th style=\"width:120px;\">上家标准佣收</th>");
        sb.Append("<th style=\"width:120px;\">上家确认佣收</th>");
        sb.Append("<th style=\"width:120px;\">上家实收</th>");
        sb.Append("<th style=\"width:120px;\">上家未收</th>");
        sb.Append("<th style=\"width:120px;\">上家折佣</th>");
        sb.Append("<th style=\"width:120px;\">上家咨询费</th>");
        sb.Append("<th style=\"width:120px;\">上家咨询费实付</th>");
        sb.Append("<th style=\"width:180px;\">上家门店</th>");
        sb.Append("<th style=\"width:180px;\">上家经纪人</th>");
        sb.Append("<th style=\"width:120px;\">上家点数</th>");
        sb.Append("<th style=\"width:120px;\" rowspan=\"2\">业绩归属时间</th>");
        sb.Append("<th style=\"width:120px;\" rowspan=\"2\">业绩确认时间</th>");
        sb.Append("<th style=\"width:120px;\" rowspan=\"2\">业绩确认人</th>");
        sb.Append("<th style=\"width:120px;\" rowspan=\"2\">编号建档人</th>");
        sb.Append("<th style=\"width:400px;\" rowspan=\"2\">补证资料</th>");
        sb.Append("<th style=\"width:400px;\" rowspan=\"2\">备注</th></tr>");
        sb.Append("<tr><th style=\"width:120px;\">客源门店</th>");
        sb.Append("<th style=\"width:120px;\">下家姓名</th>");
        sb.Append("<th style=\"width:120px;\">下家电话</th>");
        sb.Append("<th style=\"width:120px;\">下家标准佣收</th>");
        sb.Append("<th style=\"width:120px;\">下家确认佣收</th>");
        sb.Append("<th style=\"width:120px;\">下家实收</th>");
        sb.Append("<th style=\"width:120px;\">下家未收</th>");
        sb.Append("<th style=\"width:120px;\">下家折佣</th>");
        sb.Append("<th style=\"width:120px;\">下家咨询费</th>");
        sb.Append("<th style=\"width:120px;\">下家咨询费实付</th>");
        sb.Append("<th style=\"width:180px;\">下家门店</th>");
        sb.Append("<th style=\"width:180px;\">下家经纪人</th>");
        sb.Append("<th style=\"width:120px;\">下家点数</th></tr>");

        foreach (DataRow dr in dt.Rows)
        {
            sb.Append("<tr>");
            sb.AppendFormat("<td  rowspan=\"2\">{0}</td>", DatasetHelper.GetValue(dr, "LockStatus", 0)!=255?"否":"是");
            sb.AppendFormat("<td  rowspan=\"2\">{0}</td>", DatasetHelper.GetValue(dr, "bArchivement", false) ==true ?  "是":"否" );
            sb.AppendFormat("<td  rowspan=\"2\">{0}</td>", DatasetHelper.GetValue(dr, "ContractUserName", ""));
            sb.AppendFormat("<td  rowspan=\"2\">{0}</td>", DatasetHelper.GetValue(dr, "ContractCode", ""));
            sb.AppendFormat("<td  rowspan=\"2\">{0}</td>", DatasetHelper.GetValue(dr, "ContractDate", ""));
            sb.AppendFormat("<td  rowspan=\"2\">{0}</td>", DatasetHelper.GetValue(dr, "BargainType", ""));
            sb.AppendFormat("<td >{0}</td>", DatasetHelper.GetValue(dr, "VenderDepartName", ""));
            sb.AppendFormat("<td >{0}</td>", DatasetHelper.GetValue(dr, "VenderName", ""));
            sb.AppendFormat("<td >{0}</td>","-");
            sb.AppendFormat("<td  rowspan=\"2\">{0}</td>", DatasetHelper.GetValue(dr, "CustomerSource", ""));
            sb.AppendFormat("<td  rowspan=\"2\">{0}</td>", DatasetHelper.GetValue(dr, "Region", ""));
            sb.AppendFormat("<td  rowspan=\"2\">{0}</td>", DatasetHelper.GetValue(dr, "HouseAddress", ""));
            sb.AppendFormat("<td  rowspan=\"2\">{0}</td>", DatasetHelper.GetValue(dr, "Area", ""));
            sb.AppendFormat("<td  rowspan=\"2\">{0}</td>", DatasetHelper.GetValue(dr, "BargainPrice", ""));
            sb.AppendFormat("<td >{0}</td>", DatasetHelper.GetValue(dr, "VStanCommision", ""));
            sb.AppendFormat("<td >{0}</td>", DatasetHelper.GetValue(dr, "VRealCommisionFinal", ""));
            sb.AppendFormat("<td >{0}</td>", DatasetHelper.GetValue(dr, "VCommisionGeted", ""));
            sb.AppendFormat("<td >{0}</td>", DatasetHelper.GetValue(dr, "VNotGeted", ""));
            sb.AppendFormat("<td >{0}</td>", DatasetHelper.GetValue(dr, "VCommisionFinal", ""));
            sb.AppendFormat("<td >{0}</td>", DatasetHelper.GetValue(dr, "VConsultingFinal", ""));
            sb.AppendFormat("<td >{0}</td>", DatasetHelper.GetValue(dr, "VConsultingPayed", ""));
            sb.AppendFormat("<td >{0}</td>", DatasetHelper.GetValue(dr, "V_Departs", ""));
            sb.AppendFormat("<td >{0}</td>", DatasetHelper.GetValue(dr, "V_Users", ""));
            sb.AppendFormat("<td >{0}</td>", DatasetHelper.GetValue(dr, "V_Points", ""));
            sb.AppendFormat("<td  rowspan=\"2\">{0}</td>", DatasetHelper.GetValue(dr, "ArchivementDate", ""));
            sb.AppendFormat("<td  rowspan=\"2\">{0}</td>", DatasetHelper.GetValue(dr, "LastCreateArchDate", ""));
            sb.AppendFormat("<td  rowspan=\"2\">{0}</td>", DatasetHelper.GetValue(dr, "CreateArchEmp", ""));
            sb.AppendFormat("<td  rowspan=\"2\">{0}</td>", DatasetHelper.GetValue(dr, "ConfirmEmplyee", ""));
            sb.AppendFormat("<td  rowspan=\"2\">{0}</td>", DatasetHelper.GetValue(dr, "LackDocument", ""));
            sb.AppendFormat("<td  rowspan=\"2\">{0}</td></tr>", DatasetHelper.GetValue(dr, "Memo", ""));
            sb.AppendFormat("<tr><td >{0}</td>", DatasetHelper.GetValue(dr, "BuyerDepartName", ""));
            sb.AppendFormat("<td >{0}</td>", DatasetHelper.GetValue(dr, "BuyerName", ""));
            sb.AppendFormat("<td >{0}</td>","-");
            sb.AppendFormat("<td >{0}</td>", DatasetHelper.GetValue(dr, "BStanCommision", ""));
            sb.AppendFormat("<td >{0}</td>", DatasetHelper.GetValue(dr, "BRealCommisionFinal", ""));
            sb.AppendFormat("<td >{0}</td>", DatasetHelper.GetValue(dr, "BCommisionGeted", ""));
            sb.AppendFormat("<td >{0}</td>", DatasetHelper.GetValue(dr, "BNotGeted", ""));
            sb.AppendFormat("<td >{0}</td>", DatasetHelper.GetValue(dr, "BCommisionFinal", ""));
            sb.AppendFormat("<td >{0}</td>", DatasetHelper.GetValue(dr, "BConsultingFinal", ""));
            sb.AppendFormat("<td >{0}</td>", DatasetHelper.GetValue(dr, "BConsultingPayed", ""));
            sb.AppendFormat("<td >{0}</td>", DatasetHelper.GetValue(dr, "B_Departs", ""));
            sb.AppendFormat("<td >{0}</td>", DatasetHelper.GetValue(dr, "B_Users", ""));
            sb.AppendFormat("<td >{0}</td></tr>", DatasetHelper.GetValue(dr, "B_Points", ""));
        }
        
        return sb;
    }
    //零散HTML
    private StringBuilder GetLooseTable(DataTable dt)
    {
        StringBuilder sb = new StringBuilder();
        sb.Append("<table class=\"tabsorternew table_archive\"><tr>");
        sb.Append("<th style=\"width:40px;\" rowspan=\"2\">封帐</th>");
        sb.Append("<th style=\"width:40px;\" rowspan=\"2\">业绩</th>");
        sb.Append("<th style=\"width:100px;\" rowspan=\"2\">签约人员</th>");
        sb.Append("<th style=\"width:130px;\" rowspan=\"2\">成交编号</th>");
        sb.Append("<th style=\"width:100px;\" rowspan=\"2\">成交日期</th>");
        sb.Append("<th style=\"width:120px;\" rowspan=\"2\">房源门店</th>");
        sb.Append("<th style=\"width:120px;\">上家姓名</th>");
        sb.Append("<th style=\"width:120px;\">上家电话</th>");
        sb.Append("<th style=\"width:80px;\" rowspan=\"2\">客户来源</th>");
        sb.Append("<th style=\"width:60px;\" rowspan=\"2\">区域</th>");
        sb.Append("<th style=\"width:300px;\" rowspan=\"2\">房屋地址</th>");
        sb.Append("<th style=\"width:120px;\" rowspan=\"2\">面积</th>");
        sb.Append("<th style=\"width:120px;\" rowspan=\"2\">合同标的</th>");
        sb.Append("<th style=\"width:120px;\">上家确认佣收</th>");
        sb.Append("<th style=\"width:120px;\">上家实收</th>");
        sb.Append("<th style=\"width:120px;\">上家未收</th>");
        sb.Append("<th style=\"width:120px;\">上家折佣</th>");
        sb.Append("<th style=\"width:120px;\">上家咨询费</th>");
        sb.Append("<th style=\"width:120px;\">上家咨询费实付</th>");
        sb.Append("<th style=\"width:180px;\" rowspan=\"2\">业务门店</th>");
        sb.Append("<th style=\"width:180px;\" rowspan=\"2\">业务人员</th>");
        sb.Append("<th style=\"width:120px;\" rowspan=\"2\">点数</th>");
        sb.Append("<th style=\"width:120px;\" rowspan=\"2\">业绩归属时间</th>");
        sb.Append("<th style=\"width:120px;\" rowspan=\"2\">业绩确认时间</th>");
        sb.Append("<th style=\"width:120px;\" rowspan=\"2\">业绩确认人</th>");
        sb.Append("<th style=\"width:120px;\" rowspan=\"2\">编号建档人</th>");
        sb.Append("<th style=\"width:400px;\" rowspan=\"2\">备注</th></tr>");
        sb.Append("<th style=\"width:120px;\">下家姓名</th>");
        sb.Append("<th style=\"width:120px;\">下家电话</th>");
        sb.Append("<th style=\"width:120px;\">下家确认佣收</th>");
        sb.Append("<th style=\"width:120px;\">下家实收</th>");
        sb.Append("<th style=\"width:120px;\">下家未收</th>");
        sb.Append("<th style=\"width:120px;\">下家折佣</th>");
        sb.Append("<th style=\"width:120px;\">下家咨询费</th>");
        sb.Append("<th style=\"width:120px;\">下家咨询费实付</th></tr>");

        foreach (DataRow dr in dt.Rows)
        {
            sb.Append("<tr>");
            sb.AppendFormat("<td  rowspan=\"2\">{0}</td>", DatasetHelper.GetValue(dr, "LockStatus", 0) != 255 ? "否" : "是");
            sb.AppendFormat("<td  rowspan=\"2\">{0}</td>", DatasetHelper.GetValue(dr, "bArchivement", false) == true ? "是" : "否");
            sb.AppendFormat("<td  rowspan=\"2\">{0}</td>", DatasetHelper.GetValue(dr, "ContractUserName", ""));
            sb.AppendFormat("<td  rowspan=\"2\">{0}</td>", DatasetHelper.GetValue(dr, "ContractCode", ""));
            sb.AppendFormat("<td  rowspan=\"2\">{0}</td>", DatasetHelper.GetValue(dr, "ContractDate", ""));
            sb.AppendFormat("<td  rowspan=\"2\">{0}</td>", DatasetHelper.GetValue(dr, "BuyerDepartName", ""));
            sb.AppendFormat("<td >{0}</td>", DatasetHelper.GetValue(dr, "VenderName", ""));
            sb.AppendFormat("<td >{0}</td>", "-");
            sb.AppendFormat("<td  rowspan=\"2\">{0}</td>", DatasetHelper.GetValue(dr, "CustomerSource", ""));
            sb.AppendFormat("<td  rowspan=\"2\">{0}</td>", DatasetHelper.GetValue(dr, "Region", ""));
            sb.AppendFormat("<td  rowspan=\"2\">{0}</td>", DatasetHelper.GetValue(dr, "HouseAddress", ""));
            sb.AppendFormat("<td  rowspan=\"2\">{0}</td>", DatasetHelper.GetValue(dr, "Area", ""));
            sb.AppendFormat("<td  rowspan=\"2\">{0}</td>", DatasetHelper.GetValue(dr, "BargainPrice", ""));
            sb.AppendFormat("<td >{0}</td>", DatasetHelper.GetValue(dr, "VRealCommisionFinal", ""));
            sb.AppendFormat("<td >{0}</td>", DatasetHelper.GetValue(dr, "VCommisionGeted", ""));
            sb.AppendFormat("<td >{0}</td>", DatasetHelper.GetValue(dr, "VNotGeted", ""));
            sb.AppendFormat("<td >{0}</td>", DatasetHelper.GetValue(dr, "VCommisionFinal", ""));
            sb.AppendFormat("<td >{0}</td>", DatasetHelper.GetValue(dr, "VConsultingFinal", ""));
            sb.AppendFormat("<td >{0}</td>", DatasetHelper.GetValue(dr, "VConsultingPayed", ""));
            sb.AppendFormat("<td rowspan=\"2\">{0}</td>", DatasetHelper.GetValue(dr, "Departs", ""));
            sb.AppendFormat("<td rowspan=\"2\">{0}</td>", DatasetHelper.GetValue(dr, "Users", ""));
            sb.AppendFormat("<td rowspan=\"2\">{0}</td>", DatasetHelper.GetValue(dr, "Points", ""));
            sb.AppendFormat("<td  rowspan=\"2\">{0}</td>", DatasetHelper.GetValue(dr, "ArchivementDate", ""));
            sb.AppendFormat("<td  rowspan=\"2\">{0}</td>", DatasetHelper.GetValue(dr, "LastCreateArchDate", ""));
            sb.AppendFormat("<td  rowspan=\"2\">{0}</td>", DatasetHelper.GetValue(dr, "CreateArchEmp", ""));
            sb.AppendFormat("<td  rowspan=\"2\">{0}</td>", DatasetHelper.GetValue(dr, "ConfirmEmplyee", ""));
            sb.AppendFormat("<td  rowspan=\"2\">{0}</td></tr>", DatasetHelper.GetValue(dr, "Memo", ""));
            sb.AppendFormat("<td >{0}</td>", DatasetHelper.GetValue(dr, "BuyerName", ""));
            sb.AppendFormat("<td >{0}</td>", "-");
            sb.AppendFormat("<td >{0}</td>", DatasetHelper.GetValue(dr, "BRealCommisionFinal", ""));
            sb.AppendFormat("<td >{0}</td>", DatasetHelper.GetValue(dr, "BCommisionGeted", ""));
            sb.AppendFormat("<td >{0}</td>", DatasetHelper.GetValue(dr, "BNotGeted", ""));
            sb.AppendFormat("<td >{0}</td>", DatasetHelper.GetValue(dr, "BCommisionFinal", ""));
            sb.AppendFormat("<td >{0}</td>", DatasetHelper.GetValue(dr, "BConsultingFinal", ""));
            sb.AppendFormat("<td >{0}</td></tr>", DatasetHelper.GetValue(dr, "BConsultingPayed", ""));
        }

        return sb;
    }
    //其他HTML
    private StringBuilder GetOtherTable(DataTable dt)
    {
        StringBuilder sb = new StringBuilder();
        sb.Append("<table class=\"tabsorternew table_archive\"><tr>");
        sb.Append("<th style=\"width:40px;\" rowspan=\"2\">封帐</th>");
        sb.Append("<th style=\"width:40px;\" rowspan=\"2\">业绩</th>");
        sb.Append("<th style=\"width:100px;\" rowspan=\"2\">签约人员</th>");
        sb.Append("<th style=\"width:130px;\" rowspan=\"2\">成交编号</th>");
        sb.Append("<th style=\"width:100px;\" rowspan=\"2\">成交日期</th>");
        sb.Append("<th style=\"width:60px;\" rowspan=\"2\">客源门店</th>");
        sb.Append("<th style=\"width:120px;\">上家姓名</th>");
        sb.Append("<th style=\"width:120px;\">上家电话</th>");
        sb.Append("<th style=\"width:80px;\" rowspan=\"2\">客户来源</th>");
        sb.Append("<th style=\"width:400px;\" rowspan=\"2\">业务描述</th>");
        sb.Append("<th style=\"width:120px;\">上家确认佣收</th>");
        sb.Append("<th style=\"width:120px;\">上家实收</th>");
        sb.Append("<th style=\"width:120px;\">上家未收</th>");
        sb.Append("<th style=\"width:120px;\">上家折佣</th>");
        sb.Append("<th style=\"width:120px;\">上家咨询费</th>");
        sb.Append("<th style=\"width:120px;\">上家咨询费实付</th>");
        sb.Append("<th style=\"width:180px;\" rowspan=\"2\">业务门店</th>");
        sb.Append("<th style=\"width:180px;\" rowspan=\"2\">业务人员</th>");
        sb.Append("<th style=\"width:120px;\" rowspan=\"2\">点数</th>");
        sb.Append("<th style=\"width:120px;\" rowspan=\"2\">业绩归属时间</th>");
        sb.Append("<th style=\"width:120px;\" rowspan=\"2\">业绩确认时间</th>");
        sb.Append("<th style=\"width:120px;\" rowspan=\"2\">业绩确认人</th>");
        sb.Append("<th style=\"width:120px;\" rowspan=\"2\">编号建档人</th>");
        sb.Append("<th style=\"width:400px;\" rowspan=\"2\">备注</th></tr>");
        sb.Append("<th style=\"width:120px;\">下家姓名</th>");
        sb.Append("<th style=\"width:120px;\">下家电话</th>");
        sb.Append("<th style=\"width:120px;\">下家确认佣收</th>");
        sb.Append("<th style=\"width:120px;\">下家实收</th>");
        sb.Append("<th style=\"width:120px;\">下家未收</th>");
        sb.Append("<th style=\"width:120px;\">下家折佣</th>");
        sb.Append("<th style=\"width:120px;\">下家咨询费</th>");
        sb.Append("<th style=\"width:120px;\">下家咨询费实付</th></tr>");

        foreach (DataRow dr in dt.Rows)
        {
            sb.Append("<tr>");
            sb.AppendFormat("<td  rowspan=\"2\">{0}</td>", DatasetHelper.GetValue(dr, "LockStatus", 0) != 255 ? "否" : "是");
            sb.AppendFormat("<td  rowspan=\"2\">{0}</td>", DatasetHelper.GetValue(dr, "bArchivement", false) == true ? "是" : "否");
            sb.AppendFormat("<td  rowspan=\"2\">{0}</td>", DatasetHelper.GetValue(dr, "ContractUserName", ""));
            sb.AppendFormat("<td  rowspan=\"2\">{0}</td>", DatasetHelper.GetValue(dr, "ContractCode", ""));
            sb.AppendFormat("<td  rowspan=\"2\">{0}</td>", DatasetHelper.GetValue(dr, "ContractDate", ""));
            sb.AppendFormat("<td  rowspan=\"2\">{0}</td>", DatasetHelper.GetValue(dr, "BuyerDepartName", ""));
            sb.AppendFormat("<td >{0}</td>", DatasetHelper.GetValue(dr, "VenderName", ""));
            sb.AppendFormat("<td >{0}</td>", "-");
            sb.AppendFormat("<td  rowspan=\"2\">{0}</td>", DatasetHelper.GetValue(dr, "CustomerSource", ""));
            sb.AppendFormat("<td  rowspan=\"2\">{0}</td>", DatasetHelper.GetValue(dr, "BusinessDescribe", ""));
            sb.AppendFormat("<td >{0}</td>", DatasetHelper.GetValue(dr, "VRealCommisionFinal", ""));
            sb.AppendFormat("<td >{0}</td>", DatasetHelper.GetValue(dr, "VCommisionGeted", ""));
            sb.AppendFormat("<td >{0}</td>", DatasetHelper.GetValue(dr, "VNotGeted", ""));
            sb.AppendFormat("<td >{0}</td>", DatasetHelper.GetValue(dr, "VCommisionFinal", ""));
            sb.AppendFormat("<td >{0}</td>", DatasetHelper.GetValue(dr, "VConsultingFinal", ""));
            sb.AppendFormat("<td >{0}</td>", DatasetHelper.GetValue(dr, "VConsultingPayed", ""));
            sb.AppendFormat("<td rowspan=\"2\">{0}</td>", DatasetHelper.GetValue(dr, "Departs", ""));
            sb.AppendFormat("<td rowspan=\"2\">{0}</td>", DatasetHelper.GetValue(dr, "Users", ""));
            sb.AppendFormat("<td rowspan=\"2\">{0}</td>", DatasetHelper.GetValue(dr, "Points", ""));
            sb.AppendFormat("<td  rowspan=\"2\">{0}</td>", DatasetHelper.GetValue(dr, "ArchivementDate", ""));
            sb.AppendFormat("<td  rowspan=\"2\">{0}</td>", DatasetHelper.GetValue(dr, "LastCreateArchDate", ""));
            sb.AppendFormat("<td  rowspan=\"2\">{0}</td>", DatasetHelper.GetValue(dr, "CreateArchEmp", ""));
            sb.AppendFormat("<td  rowspan=\"2\">{0}</td>", DatasetHelper.GetValue(dr, "ConfirmEmplyee", ""));
            sb.AppendFormat("<td  rowspan=\"2\">{0}</td></tr>", DatasetHelper.GetValue(dr, "Memo", ""));
            sb.AppendFormat("<td >{0}</td>", DatasetHelper.GetValue(dr, "BuyerName", ""));
            sb.AppendFormat("<td >{0}</td>", "-");
            sb.AppendFormat("<td >{0}</td>", DatasetHelper.GetValue(dr, "BRealCommisionFinal", ""));
            sb.AppendFormat("<td >{0}</td>", DatasetHelper.GetValue(dr, "BCommisionGeted", ""));
            sb.AppendFormat("<td >{0}</td>", DatasetHelper.GetValue(dr, "BNotGeted", ""));
            sb.AppendFormat("<td >{0}</td>", DatasetHelper.GetValue(dr, "BCommisionFinal", ""));
            sb.AppendFormat("<td >{0}</td>", DatasetHelper.GetValue(dr, "BConsultingFinal", ""));
            sb.AppendFormat("<td >{0}</td></tr>", DatasetHelper.GetValue(dr, "BConsultingPayed", ""));
        }

        return sb;
    }
    

    //作废成交编号
    private string CancelCode(HttpContext context)
    {
        try
        {
            string modelid = context.Request.Params["modelid"];
            Chenxin.Lib.Business.Entity.t_Contract_BaseInfo baseinfo = Chenxin.Lib.Business.DAL.t_Contract_BaseInfo.GetModel(new Guid(modelid));
            if (baseinfo.Status == -1)
                return "{success:'0',msg:'该记录已作废，作废失败！',data:''}";

            baseinfo.Status = -1;
            baseinfo.UpdateCityId = CurrentUserInfo.CityId;
            baseinfo.UpdateCityName = CurrentUserInfo.CityName;
            baseinfo.UpdateCompanyId = CurrentUserInfo.CompanyId;
            baseinfo.UpdateCompanyName = CurrentUserInfo.CompanyName;
            baseinfo.UpdateDepartmentId = CurrentUserInfo.DepartId;
            baseinfo.UpdateDepartmentName = CurrentUserInfo.DepartName;
            baseinfo.UpdateUserId = CurrentUserInfo.UserId;
            baseinfo.UpdateUserName = CurrentUserInfo.UserName;
            baseinfo.UpdateTime = DateTime.Now;
            Chenxin.Lib.Business.DAL.t_Contract_BaseInfo.Update(baseinfo);

            string strMessage = "";
            Chenxin.Lib.Business.BLL.ContractBaseInfo.CaculateFinanceDeductInfo(baseinfo.ContractId, out strMessage);
            return string.Format("{{success:'1',msg:'{0}',data:''}}", "作废成功！");
        }
        catch (Exception ex)
        {
            return string.Format("{{success:'0',msg:'{0}：{1}',data:''}}", Resources.Message.Global_Err_Exception, ex.Message);
        }
    }
    
    
    //取消生成业绩
    //tianno
    //2010-9-26
    private string CancelArchivement(HttpContext context)
    {
        try
        {
            string modelid = context.Request.Params["modelid"];
            Chenxin.Lib.Business.Entity.t_Contract_BaseInfo baseinfo = Chenxin.Lib.Business.DAL.t_Contract_BaseInfo.GetModel(new Guid(modelid));
            baseinfo.ArchivementDate = null;
            baseinfo.ArchivementMonth = null;
            baseinfo.ArchivementYear = null;
            baseinfo.bArchivement = false;
            baseinfo.LastCreateArchDate = null;
            baseinfo.CreateArchDepart ="";
            baseinfo.CreateArchDepartId = Guid.Empty;
            baseinfo.CreateArchEmp = "";
            baseinfo.CreateArchEmpId = Guid.Empty;

            Chenxin.Lib.Business.DAL.t_Contract_BaseInfo.Update(baseinfo);

            string strMessage = "";
            bool bSuccess = Chenxin.Lib.Business.BLL.ContractBaseInfo.CaculateFinanceDeductInfo(baseinfo.ContractId, out strMessage);
            
            string text = string.Empty;
            text = CurrentUserInfo.UserName + "：取消业绩。成交编号：" + baseinfo.ContractCode;
            if (bSuccess)
            {
                text += ";更新实收抵扣数据成功";
            }
            else
            {
                text += ";更新试试抵扣数据失败："+strMessage;
            }
            AddLog(text, BusinessType.BusinessTypeComboList()["OprType_ContractInfo_CancelArchivement"].ToString());
            
            return string.Format("{{success:'1',msg:'{0}',data:''}}", "取消业绩成功！");
        }
        catch (Exception ex)
        {
            return string.Format("{{success:'0',msg:'{0}：{1}',data:''}}", Resources.Message.Global_Err_Exception, ex.Message);
        }
    }
    //生成业绩
    //tianno
    //2010-9-26
    private string CreatArchivement(HttpContext context)
    {
        try
        {
            string modelid = context.Request.Params["modelid"];
            DateTime ArchivementDate = DateTime.Parse(context.Request.Params["ArchivementDate"]);

            Chenxin.Lib.Business.Entity.t_Contract_BaseInfo baseinfo = Chenxin.Lib.Business.DAL.t_Contract_BaseInfo.GetModel(new Guid(modelid));

            if (baseinfo.bArchivement)
                return "{success:'0',msg:'已生成业绩，不能重复生成！',data:''}";
            
            DateTime now = DateTime.Now;
            DateTime nowdt = new DateTime(now.Year, now.Month, 1);

            if (!CurrentUserInfo.ContainsPermit(Constants.Permit_ArchivementDate))
            {
                if (ArchivementDate.CompareTo(nowdt) < 0)
                {
                    return "{success:'0',msg:'归属时间不能早于当前月，操作失败！',data:''}";
                }
            }
            
            baseinfo.ArchivementDate = ArchivementDate;
            baseinfo.ArchivementMonth = ArchivementDate.Month;
            baseinfo.ArchivementYear = ArchivementDate.Year;
            baseinfo.bArchivement = true;
            baseinfo.LastCreateArchDate = DateTime.Now;
            baseinfo.CreateArchDepart = CurrentUserInfo.DepartName;
            baseinfo.CreateArchDepartId = CurrentUserInfo.DepartId;
            baseinfo.CreateArchEmp = CurrentUserInfo.UserName;
            baseinfo.CreateArchEmpId = CurrentUserInfo.UserId;
            baseinfo.LockStatus = 255;

            Chenxin.Lib.Business.DAL.t_Contract_BaseInfo.Update(baseinfo);

            string strMessage = "";
            bool bSuccess =Chenxin.Lib.Business.BLL.ContractBaseInfo.CaculateFinanceDeductInfo(baseinfo.ContractId, out strMessage);
            
            string text = string.Empty;
            text = CurrentUserInfo.UserName + "：生成业绩。成交编号：" + baseinfo.ContractCode;
            if (bSuccess)
            {
                text += ";重新计算佣金抵扣成功";
            }
            else
            {
                text += ";重新计算佣金抵扣失败:"+strMessage;
            }
            
            
            AddLog(text, BusinessType.BusinessTypeComboList()["OprType_ContractInfo_CreatArchivement"].ToString());
                    
            return string.Format("{{success:'1',msg:'{0}',data:''}}", "生成业绩成功！");
        }
        catch (Exception ex)
        {
            return string.Format("{{success:'0',msg:'{0}：{1}',data:''}}", Resources.Message.Global_Err_Exception, ex.Message);
        }
    }
    
    //生成业绩
    //tianno
    //2010-9-26
    private string GetArchivement(HttpContext context)
    {
        try
        {
            string modelid = context.Request.Params["modelid"];
            //得到实体
            Chenxin.Lib.Business.Entity.t_Contract_BaseInfo baseinfo = Chenxin.Lib.Business.DAL.t_Contract_BaseInfo.GetModel(new Guid(modelid));

            //得到点数
            List<Chenxin.Lib.Business.Entity.t_Contract_PointAllotInfo> list = Chenxin.Lib.Business.DAL.t_Contract_PointAllotInfo.GetListArray("ContractId='"+modelid+"'");

            StringBuilder sb = new StringBuilder();
            if (list != null)
            {
                sb.Append("<div style=\"overflow-y:auto;height:90px;width:90%;margin:auto;\"><table width=\"100%\" align=\"center\" style=\"border:1px #C5D2DA solid;overflow:auot;height:35px;\" ><tr bgcolor=\"#F3F8F8\" height=\"25\"><td width=\"13%\" style=\"text-align:center;\">客户类型</td ><td width=\"13%\" style=\"text-align:center;\">业务员</td><td width=\"13%\" style=\"text-align:center;\">店长</td><td width=\"13%\" style=\"text-align:center;\">高级经理</td><td width=\"13%\" style=\"text-align:center;\">区经</td><td width=\"13%\" style=\"text-align:center;\">商经</td><td width=\"13%\" style=\"text-align:center;\">点数</td></tr>");
                foreach (Chenxin.Lib.Business.Entity.t_Contract_PointAllotInfo info in list)
                {
                    sb.AppendFormat("<tr><td style=\"text-align:center;\">{0}</td><td style=\"text-align:center;\">{1}</td><td style=\"text-align:center;\">{2}</td><td style=\"text-align:center;\">{3}</td><td style=\"text-align:center;\">{4}</td><td style=\"text-align:center;\">{5}</td><td style=\"text-align:center;\">{6}</td></tr>", info.BuyerOrVenderInfo == "10" ? "上家" : "下家", info.Employee, info.DeparterManagerName, info.MangerName.Length > 0 ? info.MangerName : "-", info.RegionManagerName.Length > 0 ? info.RegionManagerName : "-", info.MajordomoName.Length > 0 ? info.MajordomoName : "-", info.Point);
                }
                sb.Append("</table></div>");
            }

            bool flag = false;
            if (CurrentUserInfo.ContainsPermit(Constants.Permit_ArchivementDate))
                flag = true;

            return string.Format("{{success:'1',msg:'{0}',data:{{mod:{1},point:'{2}',selectAllDate:{3}}}}}", Resources.Message.Global_Msg_SUCCESS, Chenxin.Lib.Utility.JsonHelp.Convert2Json(baseinfo), sb.ToString(),flag.ToString().ToLower());
        }
        catch (Exception ex)
        {
            return string.Format("{{success:'0',msg:'{0}：{1}',data:''}}", Resources.Message.Global_Err_Exception, ex.Message);
        }
    }
    

    public string GetMultiList(HttpContext context)
    {

        try
        {
            //页码
            int strPageIndex = (string.IsNullOrEmpty(context.Request["pageindex"])) ? 1 : int.Parse(context.Request["pageindex"]) + 1;
            //页显示行数
            int strPageSize = (string.IsNullOrEmpty(context.Request["pagesize"])) ? 30 : int.Parse(context.Request["pagesize"]);
            //查询条件
            string sqlWhere = GenerateCondition(context);
            //查询分页信息
            System.Data.DataSet ds = confirmMainBusinessApply.getList(sqlWhere, strPageIndex, strPageSize);
            //总页数
            int count = (int)ds.Tables[1].Rows[0][0];
            string head = "";

            DataTable dt = ds.Tables[0];

            switch (context.Request["showtype"].ToString())
            {
                //主营业务
                case "10":
                    head = "columns.mainSaleHead";
                    break;
                case "20":
                    head = "columns.mainRentHead";
                    break;
                //零散业务
                case "30":
                    head = "columns.subHead";
                    break;
                //其他业务
                case "40":
                    head = "columns.otherHead";
                    break;
                //默认主营业务
                default:
                    head = "columns.mainHead";
                    break;
            }
            return string.Format("{{success:'1',msg:'{0}',data:{{count:'{1}',head:{3},{2}}}}}", Resources.Message.Global_Msg_SUCCESS, count, JsonHelp.Convert2Json(ds.Tables[0]),head);
        }
        catch (Exception ex)
        {
            return string.Format("{{success:'0',msg:'{0}：{1}',data:''}}", Resources.Message.Global_Err_Exception, ex.Message);
        }
    }

     //*******************************************
     //功能概要       ：查询业绩申请
     //参数説明       ：context 请求上下文
     //返回值説明     ：程序处理信息提示
     //功能詳細       ：获取业绩申请详细信息
     //作成者         ：chen.yugong
     //作成日         ：2010-06-29
     //修改者         ：
     //修改日         ：2010-07-13
     //*******************************************
    public string getList(HttpContext context)
    {
        try
        {
            //页码
            int strPageIndex = (string.IsNullOrEmpty(context.Request["pageindex"])) ? 1 : int.Parse(context.Request["pageindex"]) + 1;
            //页显示行数
            int strPageSize = (string.IsNullOrEmpty(context.Request["pagesize"])) ? 30 : int.Parse(context.Request["pagesize"]);
            //查询条件
            string sqlWhere = GenerateCondition(context);
            //查询分页信息
            System.Data.DataSet ds = confirmMainBusinessApply.getList(sqlWhere, strPageIndex, strPageSize);
            //总页数
            int count = (int)ds.Tables[1].Rows[0][0];
            
            string head = "";

            DataTable dt = ds.Tables[0];

            switch (context.Request["showtype"].ToString())
            {
                //主营业务
                case "10":
                case "20":
                    head = "columns.mainHead";
                    break;
                //零散业务
                case "30":
                    head = "columns.subHead";
                    break;
                //其他业务
                case "40":
                    head = "columns.otherHead";
                    break;
                //默认主营业务
                default:
                    break;
            }

            return string.Format("{{success:1,msg:'',data:{{count:{0},head:{1},{2}}}}}", count, head, JsonHelp.Convert2Json(dt));
        }
        catch (Exception ex)
        {
            return string.Format("{{success:'0',msg:'{0}：{1}',data:''}}", Resources.Message.Global_Err_Exception, ex.Message);
        }
    }
    //*******************************************
    //功能概要       ：查询权限
    //参数説明       ：context 请求上下文
    //返回值説明     ：程序处理信息提示
    //功能詳細       ：生成查询条件语句
    //作成者         ：chen.yugong
    //作成日         ：2010-06-29
    //修改者         ：王玮
    //修改日         ：2010-07-13
    //*******************************************
    public string GenerateCondition(HttpContext context)
    {
        try
        {
            //获取页面查询条件
            Guid city = (string.IsNullOrEmpty(context.Request["cityid"])) ? Guid.Empty : new Guid(context.Request["cityid"]);
            Guid company = (string.IsNullOrEmpty(context.Request["companyid"])) ? Guid.Empty : new Guid(context.Request["companyid"]);
            Guid businessdistrict = (string.IsNullOrEmpty(context.Request["areaid"])) ? Guid.Empty : new Guid(context.Request["areaid"]);
            Guid departs = (string.IsNullOrEmpty(context.Request["departid"])) ? Guid.Empty : new Guid(context.Request["departid"]);
            Guid employee = (string.IsNullOrEmpty(context.Request["userid"])) ? Guid.Empty : new Guid(context.Request["userid"]);

            string datetype = context.Request.QueryString["timetype"];
            string starttime = context.Request.QueryString["starttime"];
            string endtime = context.Request.QueryString["endtime"];
            string keyword = context.Request.QueryString["keyword"];
            string businesstype = context.Request.QueryString["showtype"];
            string status = context.Request.QueryString["status"];
            string region = context.Request.QueryString["region"];

            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            //判断级联菜单
            if (employee != Guid.Empty)
                sb.AppendFormat(" AND (VenderUserId = '{0}' or BuyerUserId ='{0}' or (a.ContractId in (select contractid from t_Contract_PointAllotInfo where EmployeeId='{0}'))) ", employee);
            else if (departs != Guid.Empty)
                sb.AppendFormat(" AND (VenderDepartId = '{0}' or BuyerDepartId ='{0}' or (a.ContractId in (select contractid from t_Contract_PointAllotInfo where DepartId='{0}')))", departs);
            else if (businessdistrict != Guid.Empty)
            {
                Chenxin.Lib.Hr.Entity.Hr_DepartmentInfo item = null;
                string strCachkey = string.Format(Chenxin.Lib.Cache.CacheDataType.GLOBAL_DEPARTMENT, businessdistrict);
                Chenxin.Lib.Cache.CacheService cs = new Chenxin.Lib.Cache.CacheService(Chenxin.Lib.Cache.CacheConn.xCacheConn.GLOBAL);
                item = cs.GetObject<Chenxin.Lib.Hr.Entity.Hr_DepartmentInfo>(strCachkey);
                if (!cs.Hit)
                {
                    item = Chenxin.Lib.Hr.DAL.Hr_DepartmentInfo.GetModel(businessdistrict);
                    if (item != null) cs.Set(strCachkey, item, DateTime.Now.AddDays(1));
                }

                if (item == null) return string.Format("{{success:'0',msg:'{0}',data:''}}", Resources.Message.Global_Err_GetBusDis);

                sb.AppendFormat(" and ((VenderDepartId in (Select DepartId from v_Hr_DepartmentInfo where DepartSrc like '{0}%')) or "
                    + "(BuyerDepartId in (Select DepartId from v_Hr_DepartmentInfo where DepartSrc like '{0}%')) or "
                    + "(a.ContractId in (select contractid from t_Contract_PointAllotInfo where DepartId in (Select DepartId from v_Hr_DepartmentInfo where DepartSrc like '{0}%'))))", item.DepartSrc);
            }
            else if (company != Guid.Empty)
                sb.AppendFormat(" and BuyerCompanyId = '{0}'", company);
            else if (city != Guid.Empty)
                sb.AppendFormat(" and BuyerCityId = '{0}'", city);
            else
                sb.AppendFormat(" and BuyerCompanyId = '{0}'", CurrentUserInfo.CompanyId);

            //查询权限判断权限
            System.Text.StringBuilder sb1 = new System.Text.StringBuilder();
            if (CurrentUserInfo.ContainsPermit(Constants.Permit_ViewBargaino_All))
            {
                sb1.Append(" (1=1) ");
            }
            else if (CurrentUserInfo.ContainsPermit(Constants.Permit_ViewBargain_City))
            {
                sb1.AppendFormat(" (BuyerCityId = '{0}')", CurrentUserInfo.CityId);
            }
            else if (CurrentUserInfo.ContainsPermit(Constants.Permit_ViewBargain_Company))
            {
                sb1.AppendFormat(" (BuyerCompanyId = '{0}')", CurrentUserInfo.CompanyId);
            }
            else if (CurrentUserInfo.ContainsPermit(Constants.Permit_ViewBargain_Department))
            {
                sb1.AppendFormat(" (EXISTS(Select 1 from t_Business_EmpSetting M WHERE a.VenderDepartId=M.DepartId And M.Userid= '{0}' and SearchContractApply=1)", CurrentUserInfo.UserId.ToString());
                sb1.AppendFormat(" or EXISTS(Select 1 from t_Business_EmpSetting M WHERE a.BuyerDepartId=M.DepartId And M.Userid= '{0}' and SearchContractApply=1)", CurrentUserInfo.UserId.ToString());
                sb1.AppendFormat(" or a.ContractId in (Select ContractId from t_Contract_PointAllotInfo M WHERE EXISTS(select 1 from t_Business_EmpSetting N where M.DepartId=N.DepartId and N.Userid= '{0}' and SearchBargain=1)))", CurrentUserInfo.UserId.ToString());
            }
            else
            {
                sb1.AppendFormat(" (VenderUserId = '{0}' or BuyerUserId ='{0}' or (a.ContractId in (select contractid from t_Contract_PointAllotInfo where EmployeeId='{0}'))) ", CurrentUserInfo.UserId);
            }

            if (!String.IsNullOrEmpty(sb.ToString()))
                sb1.Append(sb.ToString());
            
            if (!String.IsNullOrEmpty(starttime))
            {
                if (datetype == "10")
                    sb1.Append(string.Format(" and a.ContractDate >= '{0}'", (starttime)));
                else
                    sb1.Append(string.Format(" and a.ArchivementDate >= '{0}'", (starttime)));
            }
            if (!String.IsNullOrEmpty(endtime))
            {
                if (datetype == "10")
                    sb1.Append(string.Format(" and a.ContractDate < '{0}'", DateTime.Parse(endtime).AddDays(1)));
                else
                    sb1.Append(string.Format(" and a.ArchivementDate < '{0}'", DateTime.Parse(endtime).AddDays(1)));
            }
            if (!String.IsNullOrEmpty(status))
            {
                switch (status.Trim())
                {
                    case "10":
                        sb1.AppendFormat(" and status=1");
                        break;
                    case "-1":
                        sb1.AppendFormat(" and status=-1");
                        break;
                    case "20":
                        break;
                    default:
                        sb1.AppendFormat(" and (bArchivement={0} AND Status = 1) ", status);
                        break;
                }
            }
            if (!String.IsNullOrEmpty(businesstype))
            {
                sb1.Append(string.Format(" and ( BusinessType= {0})", businesstype));
            }
            else
            {
                sb1.Append(string.Format(" and ( BusinessType= {0})", 10));
            }
            if (!String.IsNullOrEmpty(keyword))
            {
                //sb1.Append(" and (HouseAddress LIKE '%" + keyword + "%') or (ContractCode like '%" + keyword + "%')");
                sb1.AppendFormat(" And ((HouseAddress LIKE '%{0}%') Or(ContractCode like '%{0}%') or (VenderName like '%{0}%') or (BuyerName like '%{0}%'))", keyword);
            }
            if (!String.IsNullOrEmpty(region))
            {
                sb1.AppendFormat(" And (Region LIKE '%{0}%')", region);
            }

            if (!string.IsNullOrEmpty(context.Request["rate"]))
            {
                if (context.Request["rate"].ToString() == "1")
                    sb1.Append(" and isnull(DiscountRate,1)<1 ");
                else
                    sb1.Append(" and isnull(DiscountRate,1)=1 ");
            }
            if (!string.IsNullOrEmpty(context.Request["litigation"]))
            {
                if (context.Request["litigation"].ToString() != "-1")
                    sb1.AppendFormat(" and isnull(LitigationStatus,0)={0} ", context.Request["litigation"]);
                else
                    sb1.Append(" and isnull(LitigationStatus,0)=0 ");       
            }
            
            return sb1.ToString();
        }
        catch (Exception ex)
        {
            return string.Format("{{success:'0',msg:'{0}：{1}',data:''}}", Resources.Message.Global_Err_Exception, ex.Message);
        }
    }
     //*******************************************
     //功能概要       ：生成HTML
     //参数説明       ：dslist源数据 strHtml生成后的html
     //返回值説明     ：程序处理信息提示
     //功能詳細       ：获得详细信息
     //作成者         ：chen.yugong 
     //作成日         ：2010-06-29
     //修改者         ：
     //修改日         ：
     //*******************************************
    private bool GetHtml(System.Data.DataSet dslist, out string strHtml)
     {
         try
         {
             System.Text.StringBuilder sb = new System.Text.StringBuilder();
             sb.Append("<table style=\"width:2500px; height:100%;\" cellspacing=\"1\" class=\"tabsorternew\" id=\"report\">");
             sb.Append("<thead>");
             sb.Append("<tr>");
             sb.Append("<th width=\"50px\" >封帐</th>");
             sb.Append("<th width=\"90px\" rowspan=\"2\">签约人员</th>");
             sb.Append("<th width=\"70px\" rowspan=\"2\">成交编号</th>");
             sb.Append("<th width=\"80px\" rowspan=\"2\">成交日期</th>");
             sb.Append("<th width=\"100px\" >房源门店</th>");
             sb.Append("<th width=\"70px\"  >上家姓名</th>");
             sb.Append("<th width=\"70px\"  >上家电话</th>");
             sb.Append("<th width=\"70px\" rowspan=\"2\">区域</th>");
             sb.Append("<th width=\"70px\" rowspan=\"2\">房屋地址</th>");
             sb.Append("<th width=\"70px\" rowspan=\"2\">面积</th>");
             sb.Append("<th width=\"70px\" rowspan=\"2\">合同标的</th>");
             sb.Append("<th width=\"100px\" >上家标准佣收</th>");
             sb.Append("<th width=\"100px\" >上家确认佣收</th>");
             sb.Append("<th width=\"90px\" >上家实收</th>");
             sb.Append("<th width=\"90px\" >上家未收</th>");
             sb.Append("<th width=\"70px\" >上家折佣</th>");
             sb.Append("<th width=\"90px\" >上家咨询费</th>");
             sb.Append("<th width=\"120px\" >上家咨询费实付</th>");
             sb.Append("<th width=\"70px\" >上家门店</th>");
             sb.Append("<th width=\"90px\" >上家经纪人</th>");
             sb.Append("<th width=\"70px\" >点数</th>");
             //sb.Append("<th width=\"70px\" rowspan=\"2\">业绩归属</th>");
             sb.Append("<th width=\"70px\" rowspan=\"2\">备注</th>");
             sb.Append("<th width=\"120px\" rowspan=\"2\">最后一次生业绩时间</th>");
             sb.Append("<th width=\"70px\" rowspan=\"2\">申请建档人</th>");
             sb.Append("</tr>");
             sb.Append("<tr>");
             sb.Append("<th>业绩</th>");
             sb.Append("<th>客源门店</th>");
             sb.Append("<th>下家姓名</th>");
             sb.Append("<th>下家电话</th>");
             sb.Append("<th>下家标准佣金</th>");
             sb.Append("<th>下家确认佣收</th>");
             sb.Append("<th>下家实收</th>");
             sb.Append("<th>下家未收</th>");
             sb.Append("<th>下家折佣</th>");
             sb.Append("<th>下家咨询费</th>");
             sb.Append("<th>下家咨询费实付</th>");
             sb.Append("<th>下家门店</th>");
             sb.Append("<th>下家经纪人</th>");
             sb.Append("<th>点数</th>");
             sb.Append("</tr>");
             sb.Append("</thead>");
             sb.Append("<tbody>");
            // int i = 0;
             foreach (System.Data.DataRow row in dslist.Tables[0].Rows)
             {
                // if (i % 2 == 0)
                     sb.AppendFormat("<tr id=\"{0}\" class=\"tr_houselist\">", row["ContractId"].ToString());
               //  else
               //      sb.AppendFormat("<tr id=\"{0}\" class=\"tr_houselist bluebgcolor\">", row["ContractId"].ToString());
                 //封帐
                 int lockstatus = Chenxin.Lib.Utility.DatasetHelper.GetValue(row, "LockStatus", 0);
                 if (lockstatus==0) {
                     sb.AppendFormat("<td>{0}</td>", "<input type=\"checkbox\" disabled=\"disabled\" checked=\"checked\"> ");
                 } else {
                     sb.AppendFormat("<td>{0}</td>", "<input type=\"checkbox\" disabled=\"disabled\"> ");
                 }
                 //签约人员
                 sb.AppendFormat("<td rowspan=\"2\">{0}</td>", Chenxin.Lib.Utility.DatasetHelper.GetValue(row, "ContractUserName", ""));
                 
                 //成交编号
                 sb.AppendFormat("<td rowspan=\"2\">{0}</td>", Chenxin.Lib.Utility.DatasetHelper.GetValue(row, "ContractCode", ""));
                 //成交日期
                 sb.AppendFormat("<td rowspan=\"2\">{0}</td>", Chenxin.Lib.Utility.DatasetHelper.GetValue(row, "ContractDate", ""));
                 //房源门店
                 sb.AppendFormat("<td>{0}</td>", Chenxin.Lib.Utility.DatasetHelper.GetValue(row, "VenderDepartName", ""));
                 //上家姓名
                 sb.AppendFormat("<td>{0}</td>", Chenxin.Lib.Utility.DatasetHelper.GetValue(row, "VenderName", ""));
                 //上家电话
                 string phone = Chenxin.Lib.Utility.DatasetHelper.GetValue(row, "VenderPhone", "-");
                 string mobile = Chenxin.Lib.Utility.DatasetHelper.GetValue(row, "VenderMobile", "-");
                 sb.AppendFormat("<td>{0}</td>", phone + "/" + mobile);
                 //区域
                 sb.AppendFormat("<td rowspan=\"2\">{0}</td>", Chenxin.Lib.Utility.DatasetHelper.GetValue(row, "Region", ""));
                 //房屋地址
                 sb.AppendFormat("<td rowspan=\"2\">{0}</td>", Chenxin.Lib.Utility.DatasetHelper.GetValue(row, "HouseAddress", ""));
                 //面积
                 sb.AppendFormat("<td rowspan=\"2\">{0}</td>", Chenxin.Lib.Utility.DatasetHelper.GetValue(row, "Area", ""));
                 //合同标的
                 sb.AppendFormat("<td rowspan=\"2\">{0}</td>", Chenxin.Lib.Utility.DatasetHelper.GetValue(row, "BargainPrice", ""));
                 
                 //上家标准佣收
                 sb.AppendFormat("<td>{0}</td>", Chenxin.Lib.Utility.DatasetHelper.GetValue(row, "VStanCommision", ""));
                 //上家确认佣收
                 sb.AppendFormat("<td>{0}</td>", Chenxin.Lib.Utility.DatasetHelper.GetValue(row, "VRealCommision", ""));
                 
                 //上家实收
                 sb.AppendFormat("<td>{0}</td>", Chenxin.Lib.Utility.DatasetHelper.GetValue(row, "VCommisionGeted", ""));
                 //上家未收
                 sb.AppendFormat("<td>{0}</td>", Chenxin.Lib.Utility.DatasetHelper.GetValue(row, "VCommisionGetedPayed", ""));
                 //上家折佣
                 sb.AppendFormat("<td>{0}</td>", Chenxin.Lib.Utility.DatasetHelper.GetValue(row, "VCommision", ""));
                 //上家咨询费
                 sb.AppendFormat("<td>{0}</td>", Chenxin.Lib.Utility.DatasetHelper.GetValue(row, "VConsulting", ""));
                 //上家咨询费实付
                 sb.AppendFormat("<td>{0}</td>", Chenxin.Lib.Utility.DatasetHelper.GetValue(row, "VConsultingPayed", ""));
                 //上家门店
                 sb.AppendFormat("<td>{0}</td>", Chenxin.Lib.Utility.DatasetHelper.GetValue(row, "asVDepart", ""));
                 //上家经纪人
                 sb.AppendFormat("<td>{0}</td>", Chenxin.Lib.Utility.DatasetHelper.GetValue(row, "asVEmployee", ""));
                 //点数
                 sb.AppendFormat("<td>{0}</td>", Chenxin.Lib.Utility.DatasetHelper.GetValue(row, "asVPoint", ""));
                 
                 //业绩归属
                 //sb.AppendFormat("<td rowspan=\"2\">{0}</td>", Chenxin.Lib.Utility.DatasetHelper.GetValue(row, "", ""));

                 //备注
                 sb.AppendFormat("<td rowspan=\"2\">{0}</td>", Chenxin.Lib.Utility.DatasetHelper.GetValue(row, "PointRemark", ""));
                 //最后一次生业绩时间
                 sb.AppendFormat("<td rowspan=\"2\">{0}</td>", Chenxin.Lib.Utility.DatasetHelper.GetValue(row, "LastCreateArchDate", ""));
                 //申请建档人
                 sb.AppendFormat("<td rowspan=\"2\">{0}</td>", Chenxin.Lib.Utility.DatasetHelper.GetValue(row, "ConfirmEmplyee", ""));

                 //合并行
                // if (i % 2 == 0)
                     sb.AppendFormat("<tr id=\"{0}\" class=\"tr_houselist\">", row["ContractId"].ToString());
                // else
               //      sb.AppendFormat("<tr id=\"{0}\" class=\"tr_houselist bluebgcolor\">", row["ContractId"].ToString());

                 //业绩
                 bool flg = Chenxin.Lib.Utility.DatasetHelper.GetValue(row, "bArchivement", false);
                 if(flg) {
                     sb.AppendFormat("<td>{0}</td>", "<input type=\"checkbox\" disabled=\"disabled\" checked=\"checked\"> ");
                 } else {
                     sb.AppendFormat("<td>{0}</td>", "<input type=\"checkbox\" disabled=\"disabled\" > ");
                 }
                 //客源门店
                 sb.AppendFormat("<td>{0}</td>", Chenxin.Lib.Utility.DatasetHelper.GetValue(row, "BuyerDepartName", ""));
                 //下家姓名
                 sb.AppendFormat("<td>{0}</td>", Chenxin.Lib.Utility.DatasetHelper.GetValue(row, "BuyerName", ""));
                 //下家电话
                 string bphone = Chenxin.Lib.Utility.DatasetHelper.GetValue(row, "BuyerPhone", "-");
                 string bmobile = Chenxin.Lib.Utility.DatasetHelper.GetValue(row, "BuyerMobile", "-");
                 sb.AppendFormat("<td>{0}</td>", bphone + "/" + bmobile);
                 //下家标准佣金
                 sb.AppendFormat("<td>{0}</td>", Chenxin.Lib.Utility.DatasetHelper.GetValue(row, "BStanCommision", ""));
                 //下家确认佣收
                 sb.AppendFormat("<td>{0}</td>", Chenxin.Lib.Utility.DatasetHelper.GetValue(row, "BRealCommision", ""));
                 //下家实收
                 sb.AppendFormat("<td>{0}</td>", Chenxin.Lib.Utility.DatasetHelper.GetValue(row, "BCommisionGeted", ""));
                 //下家未收
                 sb.AppendFormat("<td>{0}</td>", Chenxin.Lib.Utility.DatasetHelper.GetValue(row, "BCommisionGetedPayed", ""));
                 //下家折佣
                 sb.AppendFormat("<td>{0}</td>", Chenxin.Lib.Utility.DatasetHelper.GetValue(row, "BCommision", ""));
                 //下家咨询费
                 sb.AppendFormat("<td>{0}</td>", Chenxin.Lib.Utility.DatasetHelper.GetValue(row, "BConsulting", ""));
                 //下家咨询费实付
                 sb.AppendFormat("<td>{0}</td>", Chenxin.Lib.Utility.DatasetHelper.GetValue(row, "BConsultingPayed", ""));
                 //下家门店
                 sb.AppendFormat("<td>{0}</td>", Chenxin.Lib.Utility.DatasetHelper.GetValue(row, "asBDepart", ""));
                 //下家经纪人
                 sb.AppendFormat("<td>{0}</td>", Chenxin.Lib.Utility.DatasetHelper.GetValue(row, "asBEmployee", ""));
                 //点数
                 sb.AppendFormat("<td>{0}</td>", Chenxin.Lib.Utility.DatasetHelper.GetValue(row, "asBPoint", ""));
                 
                 sb.Append("</tr>");
                // i++;
             }
             sb.Append("</tbody></table>");
             strHtml = sb.ToString();
             return true;
         }
         catch (Exception ex)
         {
             strHtml = ex.Message;
             return false;
         }
     }

     //*******************************************
     //功能概要       ：获得详细信息
     //参数説明       ：context 请求上下文
     //返回值説明     ：程序处理信息提示
     //功能詳細       ：获得详细信息
     //作成者         ：chen.yugong 
     //作成日         ：2010-06-29
     //修改者         ：
     //修改日         ：
     //*******************************************
     public string getModel(HttpContext context)
     {
         try
         {
             string RecordId = context.Request["modelid"];
             Chenxin.Lib.Business.Entity.t_Contract_BaseInfo info = Chenxin.Lib.Business.DAL.t_Contract_BaseInfo.GetModel(new Guid(RecordId));
             if (info == null) {
                 return string.Format("{{success:'1',msg:'{0}',data:''}}", Resources.Message.Msg_Search_NoData);
             }
             return string.Format("{{success:'1',msg:'成功',data:{{model:{0}}}}}", Chenxin.Lib.Utility.JsonHelp.Convert2Json(info));
         }
         catch (Exception ex)
         {
             return string.Format("{{success:'0',msg:'{0}：{1}',data:''}}", Resources.Message.Global_Err_Exception, ex.Message);
         }
     }

     //*******************************************
     //功能概要       ：获得详细信息
     //参数説明       ：context 请求上下文
     //返回值説明     ：程序处理信息提示
     //功能詳細       ：获得详细信息
     //作成者         ：chen.yugong 
     //作成日         ：2010-06-29
     //修改者         ：
     //修改日         ：
     //*******************************************
     public string updateStatus(HttpContext context)
     {
         try
         {
             string RecordId = context.Request["modelid"];
             string flg = context.Request["flg"];
             Chenxin.Lib.Business.Entity.t_Contract_BaseInfo info = Chenxin.Lib.Business.DAL.t_Contract_BaseInfo.GetModel(new Guid(RecordId));
             if (info == null) return string.Format("{{success:'0',msg:'{0}',data:''}}", Resources.Message.Msg_Search_NoData);

             int iLockStatus = 0;
             switch (flg)
             {
                 case "0":
                     iLockStatus = 0;
                     break;
                 case"10":
                     iLockStatus = (int)info.LockStatus ^ 1;//解封资料
                     break;
                 case "20":
                     iLockStatus = (int)info.LockStatus ^ 2;//解封佣金
                     break;
                 case "30":
                     iLockStatus = (int)info.LockStatus ^ 4;//解封点数
                     break;
                 case "40":
                     iLockStatus = (int)info.LockStatus ^ 8;//解封瑕疵
                     break;
                 default:
                     iLockStatus = 255;
                     break;
             }
             info.LockStatus = iLockStatus;
             info.UpdateCityId = CurrentUserInfo.CityId;
             info.UpdateCityName = CurrentUserInfo.CityName;
             info.UpdateCompanyId = CurrentUserInfo.CompanyId;
             info.UpdateCompanyName = CurrentUserInfo.CompanyName;
             info.UpdateDepartmentId = CurrentUserInfo.DepartId;
             info.UpdateDepartmentName = CurrentUserInfo.DepartName;
             info.UpdateUserId = CurrentUserInfo.UserId;
             info.UpdateUserName = CurrentUserInfo.UserName;
             info.UpdateTime = DateTime.Now;
             Chenxin.Lib.Business.DAL.t_Contract_BaseInfo.Update(info);

             string text = string.Empty;
             switch (flg)
             {
                 case "0":
                     text = CurrentUserInfo.UserName + "：解封全部。成交编号：" + info.ContractCode;
                     AddLog(text, BusinessType.BusinessTypeComboList()["OprType_ContractInfo_OpenAll"].ToString());
                     break;
                 case "10":
                     text = CurrentUserInfo.UserName + "：解封资料。成交编号：" + info.ContractCode;
                     AddLog(text, BusinessType.BusinessTypeComboList()["OprType_ContractInfo_OpenData"].ToString());
                     break;
                 case "20":
                     text = CurrentUserInfo.UserName + "：解封佣金。成交编号：" + info.ContractCode;
                     AddLog(text, BusinessType.BusinessTypeComboList()["OprType_ContractInfo_OpenCommission"].ToString());
                     break;
                 case "30":
                     text = CurrentUserInfo.UserName + "：解封点数。成交编号：" + info.ContractCode;
                     AddLog(text, BusinessType.BusinessTypeComboList()["OprType_ContractInfo_OpenPoint"].ToString());
                     break;
                 case "40":
                     text = CurrentUserInfo.UserName + "：解封瑕疵。成交编号：" + info.ContractCode;
                     AddLog(text, BusinessType.BusinessTypeComboList()["OprType_ContractInfo_OpenFlaw"].ToString());
                     break;
                 default:                     
                    text = CurrentUserInfo.UserName + "：封帐。成交编号：" + info.ContractCode;
                    AddLog(text, BusinessType.BusinessTypeComboList()["OprType_ContractInfo_CloseAll"].ToString());
                    break;
             }
             
             return string.Format("{{success:'1',msg:'{0}',data:''}}", "操作成功！");
         }
         catch (Exception ex)
         {
             return string.Format("{{success:'0',msg:'{0}：{1}',data:''}}", Resources.Message.Global_Err_Exception, ex.Message);
         }
     }

     //*******************************************
     //功能概要       ：余款
     //参数説明       ：context 请求上下文
     //返回值説明     ：程序处理信息提示
     //功能詳細       ：余款
     //作成者         ：he.jifeng
     //作成日         ：2010-08-31
     //*******************************************
     private string getRemainPayment(HttpContext context)
     {
         string strRet = string.Empty;
         string ContractId = context.Request.Params["ContractId"];
         string InOrOut = context.Request.Params["InOrOut"];
         string FundName = context.Request.Params["FundName"];

         decimal Total = 0;
         decimal Payed = 0;
         decimal Billed = 0;
         decimal CanBill = 0;

         if (string.IsNullOrEmpty(ContractId)) return retExecResult(Constants.ExecResult.Error, Resources.Message.Err_UrlError, "");
         if (InOrOut != "1" && InOrOut != "-1") return retExecResult(Constants.ExecResult.Error, Resources.Message.Err_UrlError, "");


         Chenxin.Lib.Business.Entity.t_Contract_CommisionInfo entComm = ContractCommisionInfo.GetModel(new Guid(ContractId));
         if (entComm == null) return retExecResult(Constants.ExecResult.Error, "获取合同佣金信息失败！", "");

         DataSet dsBillInfo = ContractFinanceBillInfo.GetBilledByContractId(ContractId, InOrOut, FundName);
         if (dsBillInfo != null && dsBillInfo.Tables[0].Rows.Count > 0)
         {
             Billed = DatasetHelper.GetValue(dsBillInfo.Tables[0].Rows[0], "BillMoney", (decimal)0);
             Payed = DatasetHelper.GetValue(dsBillInfo.Tables[0].Rows[0], "PayMoney", (decimal)0);
         }

         decimal PayedCommisionFinal = 0;
         switch (FundName)
         {
             case "上家佣金":
                 Total = entComm.VRealCommisionFinal.Value;
                 break;
             case "下家佣金":
                 Total = entComm.BRealCommisionFinal.Value;
                 break;
             case "代收房款":
                 Total = entComm.CanGetSaleMoney.Value;
                 break;
             case "代收税费":
                 Total = entComm.CanGetTax.Value;
                 break;
             case "其他应收":
                 break;
             case "上家咨询费":
                 Total = entComm.VConsultingFinal.Value;
                 break;
             case "下家咨询费":
                 Total = entComm.BConsultingFinal.Value;
                 break;
             case "上家退佣":
                 DataSet dsVCommisionFinal = ContractFinanceBillInfo.GetBilledByContractId(ContractId, "1", "上家佣金");
                 PayedCommisionFinal = DatasetHelper.GetValue(dsVCommisionFinal.Tables[0].Rows[0], "PayMoney", (decimal)0);
                 Total = (PayedCommisionFinal <= entComm.VRealCommisionFinal.Value) ? 0 : PayedCommisionFinal - entComm.VRealCommisionFinal.Value;
                 break;
             case "下家退佣":
                 DataSet dsBCommisionFinal = ContractFinanceBillInfo.GetBilledByContractId(ContractId, "1", "下家佣金");
                 PayedCommisionFinal = DatasetHelper.GetValue(dsBCommisionFinal.Tables[0].Rows[0], "PayMoney", (decimal)0);
                 Total = (PayedCommisionFinal <= entComm.BRealCommisionFinal.Value) ? 0 : PayedCommisionFinal - entComm.BRealCommisionFinal.Value;
                 break;
             case "代付房款":
                 Total = entComm.GetedSaleMoney.Value;
                 break;
             case "代付税费":
                 Total = entComm.GetedTax.Value;
                 break;
             case "其他应付":
                 break;
             default:
                 break;

         }

         CanBill = Total - Billed;

         StringBuilder strHtml = new StringBuilder();
         strHtml.Append("{");
         strHtml.Append("success:'" + ((int)Constants.ExecResult.Succ).ToString() + "',");
         strHtml.Append("msg:'',");
         strHtml.AppendFormat("data:{{Total:{0},", Total);
         strHtml.AppendFormat("Payed:{0},", Payed);
         strHtml.AppendFormat("Billed:{0},", Billed);
         strHtml.AppendFormat("CanBill:{0}", CanBill);
         strHtml.Append("}");
         strHtml.Append("}");
         strRet = strHtml.ToString();

         return strRet;
     }
    
     //*******************************************
     //功能概要       ：收付开单
     //参数説明       ：context 请求上下文
     //返回值説明     ：程序处理信息提示
     //功能詳細       ：收付开单
     //作成者         ：he.jifeng
     //作成日         ：2010-08-31
     //*******************************************
     private string addBillPayment(HttpContext context)
     {
         string strRet = string.Empty;
         string ClientModel = context.Request.Params["model"];
         decimal Total = 0;
         decimal Payed = 0;
         decimal Billed = 0;
         decimal CanBill = 0;

         if (string.IsNullOrEmpty(ClientModel))
         {
             strRet = retExecResult(Constants.ExecResult.Error, Resources.Message.Err_UrlError, "");
         }
         else
         {
             ContractFinanceBillInfo bllBillInfo = new ContractFinanceBillInfo();
             ContractCommisionInfo bllComm = new ContractCommisionInfo();
             Chenxin.Lib.Business.Entity.ContractFinanceBillInfo entBillInfo = (Chenxin.Lib.Business.Entity.ContractFinanceBillInfo)JsonHelp.Convert2Entity(ClientModel, typeof(Chenxin.Lib.Business.Entity.ContractFinanceBillInfo));

             Chenxin.Lib.Business.Entity.t_Contract_BaseInfo contractBaseInfo = Chenxin.Lib.Business.DAL.t_Contract_BaseInfo.GetModel(entBillInfo.ContractId);
             if (contractBaseInfo == null)//若合同信息不存在
             {
                 strRet = retExecResult(Constants.ExecResult.Error, Resources.Message.Err_ContractNotExist, "");
                 return strRet;
             }

             Chenxin.Lib.Business.Entity.t_Contract_CommisionInfo entComm = ContractCommisionInfo.GetModel(entBillInfo.ContractId);
             if (entComm != null)
             {
                 DataSet dsBillInfo = ContractFinanceBillInfo.GetBilledByContractId(entBillInfo.ContractId.ToString(), entBillInfo.InOrOut.ToString(), entBillInfo.FundName);

                 if (dsBillInfo.Tables[0].Rows.Count > 0)
                 {
                     Billed = Convert.ToDecimal(DatasetHelper.GetValue(dsBillInfo.Tables[0].Rows[0], "BillMoney", "0"));
                     Payed = Convert.ToDecimal(DatasetHelper.GetValue(dsBillInfo.Tables[0].Rows[0], "PayMoney", "0"));
                 }

                 if (entBillInfo.InOrOut.Equals(1))
                 {
                     switch (entBillInfo.FundName)
                     {
                         case "上家佣金":
                             Total = entComm.VRealCommisionFinal.Value;
                             break;
                         case "下家佣金":
                             Total = entComm.BRealCommisionFinal.Value;
                             break;
                         case "代收房款":
                             Total = entComm.CanGetSaleMoney.Value;
                             break;
                         case "代收税费":
                             Total = entComm.CanGetTax.Value;
                             break;
                         case "其他应收":
                             break;
                         default:
                             break;
                     }
                 }
                 else if (entBillInfo.InOrOut.Equals(-1))
                 {
                     decimal PayedCommisionFinal = 0;
                     switch (entBillInfo.FundName)
                     {
                         case "上家咨询费":
                             Total = entComm.VConsultingFinal.Value;
                             break;
                         case "下家咨询费":
                             Total = entComm.BConsultingFinal.Value;
                             break;
                         case "上家退佣":
                             DataSet dsVCommisionFinal = ContractFinanceBillInfo.GetBilledByContractId(entBillInfo.ContractId.ToString(), "1", "上家佣金");
                             PayedCommisionFinal = Convert.ToDecimal(DatasetHelper.GetValue(dsVCommisionFinal.Tables[0].Rows[0], "PayMoney", "0"));
                             Total = PayedCommisionFinal - entComm.VRealCommisionFinal.Value;
                             if (Total < 0)
                             {
                                 Total = 0;
                             }
                             break;
                         case "下家退佣":
                             DataSet dsBCommisionFinal = ContractFinanceBillInfo.GetBilledByContractId(entBillInfo.ContractId.ToString(), "1", "下家佣金");
                             PayedCommisionFinal = Convert.ToDecimal(DatasetHelper.GetValue(dsBCommisionFinal.Tables[0].Rows[0], "PayMoney", "0"));
                             Total = PayedCommisionFinal - entComm.BRealCommisionFinal.Value;
                             if (Total < 0)
                             {
                                 Total = 0;
                             }
                             break;
                         case "代付房款":
                             Total = entComm.GetedSaleMoney.Value;
                             break;
                         case "代付税费":
                             Total = entComm.GetedTax.Value;
                             break;
                         case "其他应付":
                             break;
                         default:
                             break;
                     }
                 }

                 CanBill = Total - Billed;

                 if (entBillInfo.BillMoney.Value > CanBill || entBillInfo.BillMoney.Value == 0)
                 {

                     strRet = retExecResult(Constants.ExecResult.Error, Resources.Message.Err_DataUpdated, "");
                 }
                 else
                 {
                     entBillInfo.BillId = Guid.NewGuid();
                     entBillInfo.BillOprEmpId = CurrentUserInfo.UserId;
                     entBillInfo.BillOprEmpName = CurrentUserInfo.UserName;
                     entBillInfo.BillOprDepartId = CurrentUserInfo.DepartId;
                     entBillInfo.BillOprDepartName = CurrentUserInfo.DepartName;
                     entBillInfo.Status = 0;
                     entBillInfo.InputTime = DateTime.Now;
                     entBillInfo.IsFinish = false;
                     entBillInfo.ContractCityId = contractBaseInfo.BargainCityId;
                     entBillInfo.ContractCity = contractBaseInfo.BargainCityName;
                     entBillInfo.ContractCompanyId = contractBaseInfo.BargainCompanyId;
                     entBillInfo.ContractCompany = contractBaseInfo.BargainCompanyName;
                     entBillInfo.OrderPlaceId = contractBaseInfo.ContractDepartmentId;
                     

                     entBillInfo.BillCode = ContractFinanceBillInfo.GenerateCode(CurrentUserInfo.CompanyId);

                     ContractFinanceBillInfo.Add(entBillInfo);

                     string text = string.Empty;
                     text = CurrentUserInfo.UserName + "：收付开单。成交编号：" + contractBaseInfo.ContractCode + "，开单号：" + entBillInfo.BillCode;
                     AddLog(text, BusinessType.BusinessTypeComboList()["OprType_AddBill"].ToString());
                     
                     //****************获取打印信息****************************
                     Chenxin.Lib.Business.Entity.v_PrintBillInfo model = Chenxin.Lib.Business.BLL.v_PrintBillInfo.GetModel(entBillInfo.BillId);
                     if (model == null) return retExecResult(Constants.ExecResult.Error, "获取开单信息失败，请联系管理员！", "");

                     model.PrintDate = string.Format("{0:yyyy-MM-dd}", DateTime.Today);
                     string str = "";
                     Chenxin.Lib.Utility.InitialHelper.TranslateNumberToChinese(model.BillMoney.ToString(), out str);
                     model.BillMoneyBig = str;
                     model.PayMode = model.PayBankType + "/" + model.PayBankName + "/" + model.PayBankNo;
                     strRet = string.Format("{{success:1,msg:'开单成功！',data:{{model:{0}}}}}", JsonHelp.Convert2Json(model));
                     //**********************************************************
                         
                     //strRet = retExecResult(Constants.ExecResult.Succ, Resources.Message.Msg_BillPaySucc, entBillInfo.BillId);
                 }
             }
         }
         return strRet;
     }
    
     //*******************************************
     //功能概要       ：获得补证信息
     //参数説明       ：context 请求上下文
     //返回值説明     ：程序处理信息提示
     //功能詳細       ：获得补证信息
     //作成者         ：he.jifeng
     //作成日         ：2010-08-27
     //*******************************************
     private string getLackItemsInfo(HttpContext context)
     {
         string strRet = string.Empty;
         string ContractId = context.Request.Params["ContractId"];
         if (string.IsNullOrEmpty(ContractId))
         {
             strRet = retExecResult(Constants.ExecResult.Error, Resources.Message.Err_UrlError, "");
         }
         else
         {
             ContractLackItemsInfo bllLackItems = new ContractLackItemsInfo();
             DataSet ds = bllLackItems.GetModelAndIntentionCode(new Guid(ContractId));
             //Chenxin.Lib.Business.Entity.ContractLackItemsInfo entLackItems = bllLackItems.GetModel(new Guid(ContractId));
             strRet = retExecResult(Constants.ExecResult.Succ, "", JsonHelp.Convert2Json(ds));
         }
         return strRet;
     }

     //*******************************************
     //功能概要       ：处理补证信息
     //参数説明       ：context 请求上下文
     //返回值説明     ：程序处理信息提示
     //功能詳細       ：处理补证信息
     //作成者         ：he.jifeng
     //作成日         ：2010-08-27
     //*******************************************
     private string dealLackItems(HttpContext context)
     {
         string strRet = string.Empty;
         string ClientModel = context.Request.Params["model"];
         if (string.IsNullOrEmpty(ClientModel))
         {
             strRet = retExecResult(Constants.ExecResult.Error, Resources.Message.Err_UrlError, "");
         }
         else
         {
             Chenxin.Lib.Business.Entity.ContractLackItemsInfo entLackItems = (Chenxin.Lib.Business.Entity.ContractLackItemsInfo)JsonHelp.Convert2Entity(ClientModel, typeof(Chenxin.Lib.Business.Entity.ContractLackItemsInfo));
             string IntentionCode = context.Request.Params["IntentionCode"];
             string ContractCode = context.Request.Params["ContractCode"];

             //意向书编号
             if (!string.IsNullOrEmpty(IntentionCode))
             {
                 Chenxin.Lib.Business.Entity.IntentionBaseInfo entIntent = new Chenxin.Lib.Business.Entity.IntentionBaseInfo();

                 IntentionBaseInfo bllIntent = new IntentionBaseInfo();

                 List<Chenxin.Lib.Business.Entity.IntentionBaseInfo> lsIntention = bllIntent.GetListByIntentionCode(IntentionCode);

                 if (lsIntention.Count > 0)
                 {
                     //跟当前关联　未关联
                     if (lsIntention[0].ContractId.Equals(Guid.Empty) || lsIntention[0].ContractId.Equals(entLackItems.ContractId))
                     {
                         Chenxin.Lib.Business.Entity.IntentionBaseInfo entUpdIntent = lsIntention[0];
                         entUpdIntent.bContracted = true;
                         entUpdIntent.ContractId = entLackItems.ContractId;
                         entUpdIntent.ContractCode = ContractCode;

                         //旧数据
                         List<Chenxin.Lib.Business.Entity.IntentionBaseInfo> lsOldIntent = bllIntent.GetListByContractId(entLackItems.ContractId);

                         if (lsOldIntent.Count > 0)
                         {
                             lsOldIntent[0].ContractCode = "";
                             lsOldIntent[0].ContractId = Guid.Empty;
                             lsOldIntent[0].bContracted = false;
                             bllIntent.Update(lsOldIntent[0]);
                         }
                         //更新意向书
                         bllIntent.Update(entUpdIntent);

                         strRet = updLackItems(entLackItems);

                         string text = string.Empty;
                         text = CurrentUserInfo.UserName + "：个案补证。成交编号：" +ContractCode;
                         AddLog(text, BusinessType.BusinessTypeComboList()["OprType_DealLackItems"].ToString());
                     }
                     //跟其他关联
                     else
                     {
                         strRet = retExecResult(Constants.ExecResult.Succ, Resources.Message.Msg_HadRalationOfIntention, "Exist");
                     }
                 }
                 else
                 {
                     strRet = retExecResult(Constants.ExecResult.Succ, Resources.Message.Msg_NoIntention, "Nodata");
                 }
             }
             else
             {
                 strRet = updLackItems(entLackItems);
                 
                 string text = string.Empty;
                 text = CurrentUserInfo.UserName + "：个案补证。成交编号：" + ContractCode;
                 AddLog(text, BusinessType.BusinessTypeComboList()["OprType_DealLackItems"].ToString());                 
             }

         }
         
         return strRet;
     }

     private string updLackItems(Chenxin.Lib.Business.Entity.ContractLackItemsInfo entLackItems)
     {
         string strRet = string.Empty;
         ContractLackItemsInfo bllLackItems = new ContractLackItemsInfo();
         Chenxin.Lib.Business.Entity.ContractLackItemsInfo entOldLackItems = bllLackItems.GetModel(entLackItems.ContractId);

         string permitCode1 = "lack.false2true";
         string permitCode2 = "lack.freetime";
         
         //逻辑判断
         //若项目一由不缺转为缺少
         if (entOldLackItems != null)
         {
             if (entOldLackItems.IsLackItem1 == false && entLackItems.IsLackItem1 == true)
             {

                 if (CurrentUserInfo.ContainsPermit(permitCode1) == false)
                     return retExecResult(Constants.ExecResult.Succ, "您无权限将不缺件改为缺件！", "NoPermit");
             }

             //若项目二由不缺转为缺少
             if (entOldLackItems.IsLackItem2 == false && entLackItems.IsLackItem2 == true)
             {
                 if (CurrentUserInfo.ContainsPermit(permitCode1) == false)
                     return retExecResult(Constants.ExecResult.Succ, "您无权限将不缺件改为缺件！", "NoPermit");
             }

             DateTime curMonthFirtDay = DateTime.Parse(DateTime.Today.Year.ToString() + "-" + DateTime.Today.Month.ToString() + "-01");
             //若项目一原来为缺件，现在改为不缺。
             if (entOldLackItems.IsLackItem1 == true && entLackItems.IsLackItem1 == false)
             {
                 if (entLackItems.CompleteDate1.HasValue == false) return retExecResult(Constants.ExecResult.Succ, "若不缺件，必须填写项目一齐全时间！", "NoPermit");

                 //若无权限，不能齐全时间修改为上个月
                 if ((CurrentUserInfo.ContainsPermit(permitCode2) == false) && entLackItems.CompleteDate1 < curMonthFirtDay)
                     return retExecResult(Constants.ExecResult.Succ, "您无权限将齐全时间设置为之前月份！", "NoPermit");
             }

             //若项目二原来为缺件，现在改为不缺。
             if (entOldLackItems.IsLackItem2 == true && entLackItems.IsLackItem2 == false)
             {
                 if (entLackItems.CompleteDate2.HasValue == false) return retExecResult(Constants.ExecResult.Succ, "若不缺件，必须填写项目一齐全时间！", "NoPermit");
                 //若无权限，不能齐全时间修改为上个月
                 if ((CurrentUserInfo.ContainsPermit(permitCode2) == false) && entLackItems.CompleteDate2 < curMonthFirtDay)
                     return retExecResult(Constants.ExecResult.Succ, "您无权限将齐全时间设置为之前月份！", "NoPermit");
             }

             //若原来不缺。现在也是不缺）
             if (entOldLackItems.IsLackItem1 == false && entLackItems.IsLackItem1 == false)
             {
                 if (string.Format("{0:yyyy-MM-dd}", entOldLackItems.CompleteDate1) !=
                     string.Format("{0:yyyy-MM-dd}", entLackItems.CompleteDate1) && !CurrentUserInfo.ContainsPermit(permitCode2))
                     return retExecResult(Constants.ExecResult.Succ, "您无权限修改项目一的齐全时间设置！", "NoPermit");
             }

             //若原来不缺。现在也是不缺）
             if (entOldLackItems.IsLackItem2 == false && entLackItems.IsLackItem2 == false)
             {
                 if (entOldLackItems.CompleteDate2 != entLackItems.CompleteDate2 && !CurrentUserInfo.ContainsPermit(permitCode2))
                     return retExecResult(Constants.ExecResult.Succ, "您无权限修改项目二的齐全时间设置！", "NoPermit");
             }
         }
         
         //完备与否的判断
         if (entLackItems.IsLackItem1.Equals(false))
         {
             entLackItems.LackItems1 = "";
             entLackItems.LackOthers1 = "";
         }
         if (entLackItems.IsLackItem2.Equals(false))
         {
             entLackItems.LackItems2 = "";
             entLackItems.LackOthers2 = "";
         }
         //更新
         if (entOldLackItems != null)
         {
             entLackItems.UpdatePerson = CurrentUserInfo.UserName;
             entLackItems.UpdatePersonId = CurrentUserInfo.UserId;
             entLackItems.Updatetime = DateTime.Now;
             entLackItems.Addtime = entOldLackItems.Addtime;

             bllLackItems.Update(entLackItems);
             strRet = retExecResult(Constants.ExecResult.Succ, Resources.Message.Msg_Update_Success, "");
         }
         //添加
         else
         {
             entLackItems.UpdatePerson = CurrentUserInfo.UserName;
             entLackItems.UpdatePersonId = CurrentUserInfo.UserId;
             entLackItems.Updatetime = DateTime.Now;
             entLackItems.Addtime = DateTime.Now;

             bllLackItems.Add(entLackItems);
             strRet = retExecResult(Constants.ExecResult.Succ, Resources.Message.Msg_Insert_Success, "");
         }
         return strRet;
     }
    
     //*******************************************
     //功能概要       ：添加成交附件
     //参数説明       ：context 请求上下文
     //返回值説明     ：程序处理信息提示
     //功能詳細       ：添加成交附件
     //作成者         ：he.jifeng
     //作成日         ：2010-08-30
     //*******************************************
     private string addContractAtt(HttpContext context)
     {
        string strRet = string.Empty;
        ContractAttachment bllContract = new ContractAttachment();
         
        Chenxin.Lib.Business.Entity.ContractAttachment entAtt = (Chenxin.Lib.Business.Entity.ContractAttachment)JsonHelp.Convert2Entity(context.Request.Params["model"], typeof(Chenxin.Lib.Business.Entity.ContractAttachment));

        entAtt.RecordId = Guid.NewGuid();
        entAtt.AttType = 10;
        entAtt.AddTime = DateTime.Now;
        entAtt.CityId = CurrentUserInfo.CityId;
        entAtt.CityName = CurrentUserInfo.CityName;
        entAtt.CompanyId = CurrentUserInfo.CompanyId;
        entAtt.CompanyName = CurrentUserInfo.CompanyName;
        entAtt.DepartId = CurrentUserInfo.DepartId;
        entAtt.DepartName = CurrentUserInfo.DepartName;
        entAtt.UserId = CurrentUserInfo.UserId;
        entAtt.UserName = CurrentUserInfo.UserName;
         
        if (!string.IsNullOrEmpty(entAtt.Path))
        {
            entAtt.Path = Constants.FilePath_Contract + entAtt.Path;
        }

        bllContract.Add(entAtt);
        strRet = retExecResult(Constants.ExecResult.Succ, Resources.Message.Msg_UploadFile_Succ, "");

        return strRet;
     }

     //*******************************************
     //功能概要       ：检查意向书编号
     //参数説明       ：context 请求上下文
     //返回值説明     ：程序处理信息提示
     //功能詳細       ：检查意向书编号
     //作成者         ：he.jifeng
     //作成日         ：2010-08-30
     //*******************************************
     private string chkIntentionCode(HttpContext context)
     {
         string strRet = string.Empty;
         IntentionBaseInfo bllInte = new IntentionBaseInfo();
         string IntentionCode = context.Request.Params["IntentionCode"];
         string ContractId = context.Request.Params["ContractId"];

         List<Chenxin.Lib.Business.Entity.IntentionBaseInfo> lsIntention = bllInte.GetListByIntentionCode(IntentionCode);

         if (lsIntention.Count > 0)
         {
             //跟自己关联
             if (lsIntention[0].ContractId.Equals(Guid.Empty) || lsIntention[0].ContractId.Equals(new Guid(ContractId)))
             {
                 strRet = retExecResult(Constants.ExecResult.Succ, "", "");
             }
             //跟其他关联或未关联
             else
             {
                 strRet = retExecResult(Constants.ExecResult.Succ, Resources.Message.Msg_HadRalationOfIntention, "Exist");
             }
         }
         else
         {
             strRet = retExecResult(Constants.ExecResult.Succ, Resources.Message.Msg_NoIntention, "Nodata");
         }
         return strRet;
     }

     //*******************************************
     //功能概要       ：获取佣收调整历史
     //参数説明       ：context 请求上下文
     //返回值説明     ：程序处理信息提示
     //功能詳細       ：获取佣收调整历史
     //作成者         ：he.jifeng
     //作成日         ：2010-09-17
     //*******************************************
     private string getAdjustInfoList(HttpContext context)
     {
         string strRet = string.Empty;
         string strParam = string.Empty;
         string ContractCode = context.Request.Params["ContractCode"];
         StringBuilder strHtml = new StringBuilder();
         Dictionary<string,string> dicParams = new Dictionary<string,string>();
         
         if (string.IsNullOrEmpty(ContractCode))
         {
             strRet = retExecResult(Constants.ExecResult.Error, Resources.Message.Err_UrlError, "");
         }
         else
         {
             strParam = context.Request.Params["pagesize"];
             if (!string.IsNullOrEmpty(strParam))
             {
                 dicParams.Add("PageSize", strParam);
             }
             strParam = context.Request.Params["pageindex"];
             if (!string.IsNullOrEmpty(strParam))
             {
                 dicParams.Add("PageIndex", strParam);
             }
             strParam = context.Request.Params["sort"];
             if (!string.IsNullOrEmpty(strParam))
             {
                 dicParams.Add("Sort", strParam);
             }
             dicParams.Add("ContractCode",ContractCode);

             ContractCommisionAdjustInfo bllAdj = new ContractCommisionAdjustInfo();
             DataSet dsAdj = bllAdj.GetListByContractCode(dicParams);
             
            strHtml.Append("{");
            strHtml.Append("success:'" + ((int)Constants.ExecResult.Succ).ToString() + "',");
            strHtml.Append("msg:'',");
            strHtml.AppendFormat("data:{{{0},", Chenxin.Lib.Utility.JsonHelp.Convert2Json(dsAdj.Tables[0]));
            strHtml.AppendFormat("count:'{0}'", dsAdj.Tables[1].Rows[0][0]);
            strHtml.Append("}");
            strHtml.Append("}");

            strRet = strHtml.ToString();
         }
         return strRet;
     }

     //*******************************************
     //功能概要       ：获取调整前及实际佣收
     //参数説明       ：context 请求上下文
     //返回值説明     ：程序处理信息提示
     //功能詳細       ：获取调整前及实际佣收
     //作成者         ：he.jifeng
     //作成日         ：2010-09-17
     //*******************************************
     private string getBeforeRealMoney(HttpContext context)
     {
         string strRet = string.Empty;
         StringBuilder strHtml = new StringBuilder();
         string ContractId = context.Request.Params["ContractId"];
         string AdjustType = context.Request.Params["AdjustType"];
         string FoundName = string.Empty;
         decimal dBeforeMoney = 0;

         if (string.IsNullOrEmpty(AdjustType) || string.IsNullOrEmpty(ContractId))
         {
             strRet = retExecResult(Constants.ExecResult.Error, Resources.Message.Err_UrlError, "");
         }
         else
         {
             ContractFinanceBillInfo bllBillInfo = new ContractFinanceBillInfo();
             ContractCommisionInfo bllComm = new ContractCommisionInfo();
             DataSet dsComm = ContractCommisionInfo.GetCommisionInfo(ContractId);

             switch (AdjustType)
             {
                 case "10":
                     FoundName = "上家佣金";
                     dBeforeMoney = (decimal)dsComm.Tables[0].Rows[0]["VRealCommision"];
                     break;
                 case "20":
                     FoundName = "下家佣金";
                     dBeforeMoney = (decimal)dsComm.Tables[0].Rows[0]["BRealCommision"];
                     break;
                 case "30":
                     FoundName = "上家咨询费";
                     dBeforeMoney = (decimal)dsComm.Tables[0].Rows[0]["VConsulting"];
                     break;
                 case "40":
                     FoundName = "下家咨询费";
                     dBeforeMoney = (decimal)dsComm.Tables[0].Rows[0]["BConsulting"];
                     break;
                 default:
                     break;
             }
             strHtml.Append("{");
             strHtml.Append("success:'" + ((int)Constants.ExecResult.Succ).ToString() + "',");
             strHtml.Append("msg:'',");
             strHtml.Append("data:{");
             strHtml.AppendFormat("BeforeMoney:{0},", dBeforeMoney);
             strHtml.AppendFormat("PayedMoney:{0}", ContractFinanceBillInfo.GetPayedMoney(new Guid(ContractId), FoundName));
             strHtml.Append("}");
             strHtml.Append("}");
             strRet = strHtml.ToString();
         }
         return strRet;
     }
    
     //*******************************************
     //功能概要       ：调整佣收
     //参数説明       ：context 请求上下文
     //返回值説明     ：程序处理信息提示
     //功能詳細       ：调整佣收
     //作成者         ：he.jifeng
     //作成日         ：2010-09-17
     //*******************************************
     private string adjestCommision(HttpContext context)
     {
         string strRet = string.Empty;
         string ClientModel = context.Request.Params["model"];
         Chenxin.Lib.Business.Entity.ContractCommisionAdjustInfo entAdjInfo = (Chenxin.Lib.Business.Entity.ContractCommisionAdjustInfo)JsonHelp.Convert2Entity(ClientModel, typeof(Chenxin.Lib.Business.Entity.ContractCommisionAdjustInfo));
         if (string.IsNullOrEmpty(ClientModel))
         {
             strRet = retExecResult(Constants.ExecResult.Error, Resources.Message.Err_UrlError, "");
         }
         else
         {
             ContractCommisionAdjustInfo bllAdjInfo = new ContractCommisionAdjustInfo();
             

             entAdjInfo.RecordId = Guid.NewGuid();
             entAdjInfo.Status = 1;
             entAdjInfo.AddCity = CurrentUserInfo.CityName;
             entAdjInfo.AddCityId = CurrentUserInfo.CityId;
             entAdjInfo.AddCompany = CurrentUserInfo.CompanyName;
             entAdjInfo.AddCompanyId = CurrentUserInfo.CompanyId;
             entAdjInfo.AddDepart = CurrentUserInfo.DepartName;
             entAdjInfo.AddDepartId = CurrentUserInfo.DepartId;
             entAdjInfo.AddEmployee = CurrentUserInfo.UserName;
             entAdjInfo.AddEmployeeId = CurrentUserInfo.UserId;
             entAdjInfo.Addtime = DateTime.Now;

             bllAdjInfo.Add(entAdjInfo);
             updCommisionInfo(entAdjInfo);
             UpdateContractLockStatus(entAdjInfo.ContractId);

             string text = string.Empty;
             text = CurrentUserInfo.UserName + "：调整佣收。成交编号：" + entAdjInfo.ContractCode;
             AddLog(text, BusinessType.BusinessTypeComboList()["OprType_AdjestCommision"].ToString());
             
             strRet = retExecResult(Constants.ExecResult.Succ,Resources.Message.Msg_AdjestComm_Succ, "");
             
         }
         return strRet;
     }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="contractId"></param>
     private void UpdateContractLockStatus(Guid contractId)
     {
         Chenxin.Lib.Business.Entity.t_Contract_BaseInfo baseInfo =
             Chenxin.Lib.Business.DAL.t_Contract_BaseInfo.GetModel(contractId);
         baseInfo.LockStatus = 255;
         
         Chenxin.Lib.Business.DAL.t_Contract_BaseInfo.Update(baseInfo);
     }
     //*******************************************
     //功能概要       ：更新佣收信息
     //参数説明       ：context 请求上下文
     //返回值説明     ：程序处理信息提示
     //功能詳細       ：更新佣收信息
     //作成者         ：he.jifeng
     //作成日         ：2010-09-19
     //*******************************************
     private void updCommisionInfo(Chenxin.Lib.Business.Entity.ContractCommisionAdjustInfo entAdjInfo)
     {
         ContractCommisionInfo bllComm = new ContractCommisionInfo();

         Chenxin.Lib.Business.Entity.t_Contract_CommisionInfo entComm = ContractCommisionInfo.GetModel(entAdjInfo.ContractId);

         switch (entAdjInfo.AdjustType)
         {
             case 10:
                 entComm.VRealCommisionFinal = entComm.VRealCommisionFinal + entAdjInfo.AdjustMoney;
                 break;
             case 20:
                 entComm.BRealCommisionFinal = entComm.BRealCommisionFinal + entAdjInfo.AdjustMoney;
                 break;
             case 30:
                 entComm.VConsultingFinal = entComm.VConsultingFinal + entAdjInfo.AdjustMoney;
                 break;
             case 40:
                 entComm.BConsultingFinal = entComm.BConsultingFinal + entAdjInfo.AdjustMoney;
                 break;
             default:
                 break;
         }
         ContractCommisionInfo.Update(entComm);
     }

     //*******************************************
     //功能概要       ：登记房费，税费应收
     //参数説明       ：context 请求上下文
     //返回值説明     ：程序处理信息提示
     //功能詳細       ：登记房费，税费应收
     //作成者         ：he.jifeng
     //作成日         ：2010-09-20
     //*******************************************
     private string regIncome(HttpContext context)
     {
         string strRet = string.Empty;
         string ClientModel = context.Request.Params["model"];
         string IncomeType = context.Request.Params["IncomeType"];
         
         if (string.IsNullOrEmpty(ClientModel))
         {
             strRet = retExecResult(Constants.ExecResult.Error, Resources.Message.Err_UrlError, "");
         }
         else
         {
             ContractCommisionInfo bllComm = new ContractCommisionInfo();
             ContractCommisionIncomeHistory bllIncomeHis = new ContractCommisionIncomeHistory();

             Chenxin.Lib.Business.Entity.ContractCommisionIncomeHistory entIncomeHis = new Chenxin.Lib.Business.Entity.ContractCommisionIncomeHistory();
             
             Chenxin.Lib.Business.Entity.t_Contract_CommisionInfo entComm = (Chenxin.Lib.Business.Entity.t_Contract_CommisionInfo)JsonHelp.Convert2Entity(ClientModel, typeof(Chenxin.Lib.Business.Entity.t_Contract_CommisionInfo));

             Chenxin.Lib.Business.Entity.t_Contract_CommisionInfo entUpdComm = ContractCommisionInfo.GetModel(entComm.ContractId);

             entUpdComm.UpdateEmployee = CurrentUserInfo.UserName;
             entUpdComm.UpdateEmployeeId = CurrentUserInfo.UserId;
             entUpdComm.UpdateTime = DateTime.Now;

             entIncomeHis.RecordId = Guid.NewGuid();
             entIncomeHis.ContractId = entComm.ContractId;
             entIncomeHis.AddDepartId = CurrentUserInfo.DepartId;
             entIncomeHis.AddDepartName = CurrentUserInfo.DepartName;
             entIncomeHis.AddUserId = CurrentUserInfo.UserId;
             entIncomeHis.AddUserName = CurrentUserInfo.UserName;
             entIncomeHis.AddTime = DateTime.Now;
             entIncomeHis.IncomeType = IncomeType;
             if (IncomeType.Equals("代收房款"))
             {
                 entIncomeHis.Income = entComm.CanGetSaleMoney;
                 entUpdComm.CanGetSaleMoney = entUpdComm.CanGetSaleMoney + entComm.CanGetSaleMoney;
             }
             else
             {
                 entIncomeHis.Income = entComm.CanGetTax;
                 entUpdComm.CanGetTax = entUpdComm.CanGetTax + entComm.CanGetTax;
             }

             ContractCommisionInfo.Update(entUpdComm);
             bllIncomeHis.Add(entIncomeHis);

             Chenxin.Lib.Business.Entity.t_Contract_BaseInfo baseinfo = Chenxin.Lib.Business.DAL.t_Contract_BaseInfo.GetModel(entUpdComm.ContractId);
                 
             string text = string.Empty;
             text = CurrentUserInfo.UserName + "：应收登记。成交编号：" + baseinfo.ContractCode;
             AddLog(text, BusinessType.BusinessTypeComboList()["OprType_RegIncome"].ToString());
             
             strRet = retExecResult(Constants.ExecResult.Succ, Resources.Message.Msg_RegIncome_Succ, "");
         }
         return strRet;
     }

     //*******************************************
     //功能概要       ：获取应收历史
     //参数説明       ：context 请求上下文
     //返回值説明     ：程序处理信息提示
     //功能詳細       ：获取应收历史
     //作成者         ：he.jifeng
     //作成日         ：2010-09-20
     //*******************************************
     private string getIncomeHistory(HttpContext context)
     {
         string strRet = string.Empty;
         StringBuilder strHtml = new StringBuilder();
         ContractCommisionIncomeHistory bllIncomeHis = new ContractCommisionIncomeHistory();
         Dictionary<string, string> dicParams = new Dictionary<string, string>();

         string ContractId = context.Request.Params["ContractId"];
         string IncomeType = context.Request.Params["IncomeType"];
         string strParam = string.Empty;
         
         
         if (string.IsNullOrEmpty(ContractId))
         {
             strRet = retExecResult(Constants.ExecResult.Error, Resources.Message.Err_UrlError, "");
         }
         else
         {
             strParam = context.Request.Params["pagesize"];
             if (!string.IsNullOrEmpty(strParam))
             {
                 dicParams.Add("PageSize", strParam);
             }
             strParam = context.Request.Params["pageindex"];
             if (!string.IsNullOrEmpty(strParam))
             {
                 dicParams.Add("PageIndex", strParam);
             }
             strParam = context.Request.Params["sort"];
             if (!string.IsNullOrEmpty(strParam))
             {
                 dicParams.Add("Sort", strParam);
             }
             dicParams.Add("ContractId",ContractId);
             dicParams.Add("IncomeType", IncomeType);

             DataSet dsHis = bllIncomeHis.GetListByParams(dicParams);
             
            strHtml.Append("{");
            strHtml.Append("success:'" + ((int)Constants.ExecResult.Succ).ToString() + "',");
            strHtml.Append("msg:'',");
            strHtml.AppendFormat("data:{{{0},", Chenxin.Lib.Utility.JsonHelp.Convert2Json(dsHis.Tables[0]));
            strHtml.AppendFormat("count:'{0}'", dsHis.Tables[1].Rows[0][0]);
            strHtml.Append("}");
            strHtml.Append("}");

            strRet = strHtml.ToString();
         }

         return strRet;
     }
     
}